1<?php
2namespace 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
17use TYPO3\CMS\Backend\Template\ModuleTemplate;
18use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
19use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
20use 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 */
26class BackendTemplateView implements ViewInterface
27{
28    /**
29     * @var ModuleTemplate
30     */
31    protected $moduleTemplate;
32
33    /**
34     * @var TemplateView
35     */
36    protected $templateView;
37
38    /**
39     * @param ModuleTemplate $moduleTemplate
40     */
41    public function injectModuleTemplate(ModuleTemplate $moduleTemplate)
42    {
43        $this->moduleTemplate = $moduleTemplate;
44    }
45
46    /**
47     * @param TemplateView $templateView
48     */
49    public function injectTemplateView(TemplateView $templateView)
50    {
51        $this->templateView = $templateView;
52    }
53
54    /**
55     * @return ModuleTemplate
56     */
57    public function getModuleTemplate()
58    {
59        return $this->moduleTemplate;
60    }
61
62    /**
63     * Loads the template source and render the template.
64     * If "layoutName" is set in a PostParseFacet callback, it will render the file with the given layout.
65     *
66     * Additionally amends the rendered template with a module template "frame"
67     *
68     * @param string $actionName If set, the view of the specified action will be rendered instead. Default is the action specified in the Request object
69     * @return string Rendered Template
70     */
71    public function render($actionName = null)
72    {
73        $actionViewContent = $this->templateView->render($actionName);
74        $this->moduleTemplate->setContent($actionViewContent);
75        return $this->moduleTemplate->renderContent();
76    }
77
78    /**
79     * Sets the current controller context
80     *
81     * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext Controller context which is available inside the view
82     */
83    public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
84    {
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     */
95    public function assign($key, $value)
96    {
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     */
108    public function assignMultiple(array $values)
109    {
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     */
120    public function canRender(ControllerContext $controllerContext)
121    {
122        return $this->templateView->canRender($controllerContext);
123    }
124
125    /**
126     * Init view
127     */
128    public function initializeView()
129    {
130        $this->templateView->initializeView();
131    }
132
133    /**
134     * Set the root path(s) to the templates.
135     *
136     * @param array $templateRootPaths Root path(s) to the templates.
137     */
138    public function setTemplateRootPaths(array $templateRootPaths)
139    {
140        $this->templateView->setTemplateRootPaths($templateRootPaths);
141    }
142
143    /**
144     * Set the root path(s) to the partials.
145     *
146     * @param array $partialRootPaths Root paths to the partials.
147     */
148    public function setPartialRootPaths(array $partialRootPaths)
149    {
150        $this->templateView->setPartialRootPaths($partialRootPaths);
151    }
152
153    /**
154     * Set the root path(s) to the layouts.
155     *
156     * @param array $layoutRootPaths Root path to the layouts.
157     */
158    public function setLayoutRootPaths(array $layoutRootPaths)
159    {
160        $this->templateView->setLayoutRootPaths($layoutRootPaths);
161    }
162}
163