[FOLLOWUP][BUGFIX] Revert BackendActionController in favor of BackendView
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / View / BackendTemplateView.php
1 <?php
2 namespace TYPO3\CMS\Backend\View;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Template\ModuleTemplate;
18 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
19 use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
20 use TYPO3\CMS\Fluid\View\TemplateView;
21
22 /**
23 * Decorates the main template view. Should be used as view if you want to use
24 * Fluid templates in a backend module in order to have a consistent backend.
25 *
26 * @api
27 */
28 class BackendTemplateView implements ViewInterface {
29
30 /**
31 * @var ModuleTemplate
32 */
33 protected $moduleTemplate;
34
35 /**
36 * @var TemplateView
37 */
38 protected $templateView;
39
40 /**
41 * @param ModuleTemplate $moduleTemplate
42 */
43 public function injectModuleTemplate(ModuleTemplate $moduleTemplate) {
44 $this->moduleTemplate = $moduleTemplate;
45 }
46
47 /**
48 * @param TemplateView $templateView
49 */
50 public function injectTemplateView(TemplateView $templateView) {
51 $this->templateView = $templateView;
52 }
53
54 /**
55 * @return ModuleTemplate
56 */
57 public function getModuleTemplate() {
58 return $this->moduleTemplate;
59 }
60
61 /**
62 * Loads the template source and render the template.
63 * If "layoutName" is set in a PostParseFacet callback, it will render the file with the given layout.
64 *
65 * Additionally amends the rendered template with a module template "frame"
66 *
67 * @param string $actionName If set, the view of the specified action will be rendered instead. Default is the action specified in the Request object
68 * @return string Rendered Template
69 * @api
70 */
71 public function render($actionName = NULL) {
72 $actionViewContent = $this->templateView->render($actionName);
73 $this->moduleTemplate->setContent($actionViewContent);
74 return $this->moduleTemplate->renderContent();
75 }
76
77 /**
78 * Sets the current controller context
79 *
80 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext Controller context which is available inside the view
81 * @return void
82 * @api
83 */
84 public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext) {
85 $this->templateView->setControllerContext($controllerContext);
86 }
87
88 /**
89 * Assign a value to the variable container.
90 *
91 * @param string $key The key of a view variable to set
92 * @param mixed $value The value of the view variable
93 * @return \TYPO3\CMS\Fluid\View\AbstractTemplateView the instance of this view to allow chaining
94 * @api
95 */
96 public function assign($key, $value) {
97 $this->templateView->assign($key, $value);
98 return $this;
99 }
100
101 /**
102 * Assigns multiple values to the JSON output.
103 * However, only the key "value" is accepted.
104 *
105 * @param array $values Keys and values - only a value with key "value" is considered
106 * @return \TYPO3\CMS\Fluid\View\AbstractTemplateView the instance of this view to allow chaining
107 * @api
108 */
109 public function assignMultiple(array $values) {
110 $this->templateView->assignMultiple($values);
111 return $this;
112 }
113
114 /**
115 * Checks whether a template can be resolved for the current request context.
116 *
117 * @param ControllerContext $controllerContext Controller context which is available inside the view
118 * @return bool
119 * @api
120 */
121 public function canRender(ControllerContext $controllerContext) {
122 return $this->templateView->canRender($controllerContext);
123 }
124
125 /**
126 * Init view
127 */
128 public function initializeView() {
129 $this->templateView->initializeView();
130 }
131
132 }