[BUGFIX] Show spaces of content elements in page module
[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\Controller\ControllerContext;
19 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
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 {
45 $this->moduleTemplate = $moduleTemplate;
46 }
47
48 /**
49 * @param TemplateView $templateView
50 */
51 public function injectTemplateView(TemplateView $templateView)
52 {
53 $this->templateView = $templateView;
54 }
55
56 /**
57 * @return ModuleTemplate
58 */
59 public function getModuleTemplate()
60 {
61 return $this->moduleTemplate;
62 }
63
64 /**
65 * Loads the template source and render the template.
66 * If "layoutName" is set in a PostParseFacet callback, it will render the file with the given layout.
67 *
68 * Additionally amends the rendered template with a module template "frame"
69 *
70 * @param string $actionName If set, the view of the specified action will be rendered instead. Default is the action specified in the Request object
71 * @return string Rendered Template
72 * @api
73 */
74 public function render($actionName = null)
75 {
76 $actionViewContent = $this->templateView->render($actionName);
77 $this->moduleTemplate->setContent($actionViewContent);
78 return $this->moduleTemplate->renderContent();
79 }
80
81 /**
82 * Sets the current controller context
83 *
84 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext Controller context which is available inside the view
85 * @api
86 */
87 public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
88 {
89 $this->templateView->setControllerContext($controllerContext);
90 }
91
92 /**
93 * Assign a value to the variable container.
94 *
95 * @param string $key The key of a view variable to set
96 * @param mixed $value The value of the view variable
97 * @return \TYPO3\CMS\Fluid\View\AbstractTemplateView the instance of this view to allow chaining
98 * @api
99 */
100 public function assign($key, $value)
101 {
102 $this->templateView->assign($key, $value);
103 return $this;
104 }
105
106 /**
107 * Assigns multiple values to the JSON output.
108 * However, only the key "value" is accepted.
109 *
110 * @param array $values Keys and values - only a value with key "value" is considered
111 * @return \TYPO3\CMS\Fluid\View\AbstractTemplateView the instance of this view to allow chaining
112 * @api
113 */
114 public function assignMultiple(array $values)
115 {
116 $this->templateView->assignMultiple($values);
117 return $this;
118 }
119
120 /**
121 * Checks whether a template can be resolved for the current request context.
122 *
123 * @param ControllerContext $controllerContext Controller context which is available inside the view
124 * @return bool
125 * @api
126 */
127 public function canRender(ControllerContext $controllerContext)
128 {
129 return $this->templateView->canRender($controllerContext);
130 }
131
132 /**
133 * Init view
134 */
135 public function initializeView()
136 {
137 $this->templateView->initializeView();
138 }
139
140 /**
141 * Set the root path(s) to the templates.
142 *
143 * @param array $templateRootPaths Root path(s) to the templates.
144 * @api
145 */
146 public function setTemplateRootPaths(array $templateRootPaths)
147 {
148 $this->templateView->setTemplateRootPaths($templateRootPaths);
149 }
150
151 /**
152 * Set the root path(s) to the partials.
153 *
154 * @param array $partialRootPaths Root paths to the partials.
155 * @api
156 */
157 public function setPartialRootPaths(array $partialRootPaths)
158 {
159 $this->templateView->setPartialRootPaths($partialRootPaths);
160 }
161
162 /**
163 * Set the root path(s) to the layouts.
164 *
165 * @param array $layoutRootPaths Root path to the layouts.
166 * @api
167 */
168 public function setLayoutRootPaths(array $layoutRootPaths)
169 {
170 $this->templateView->setLayoutRootPaths($layoutRootPaths);
171 }
172 }