[TASK] Streamline phpdoc annotations in EXT:fluid
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / View / AbstractTemplateView.php
1 <?php
2 namespace TYPO3\CMS\Fluid\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\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Extbase\Object\ObjectManager;
19 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
20 use TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException;
21 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
22 use TYPO3Fluid\Fluid\View\TemplateView;
23
24 /**
25 * Abstract Fluid Template View.
26 *
27 * Contains the fundamental methods which any Fluid based template view needs.
28 */
29 abstract class AbstractTemplateView extends TemplateView implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface
30 {
31 /**
32 * @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
33 */
34 protected $controllerContext;
35
36 /**
37 * Initializes this view.
38 */
39 public function initializeView()
40 {
41 }
42
43 /**
44 * @param RenderingContextInterface $context
45 * @internal
46 */
47 public function __construct(RenderingContextInterface $context = null)
48 {
49 if (!$context) {
50 $context = GeneralUtility::makeInstance(ObjectManager::class)->get(RenderingContext::class, $this);
51 }
52 parent::__construct($context);
53 }
54
55 /**
56 * Tells if the view implementation can render the view for the given context.
57 *
58 * By default we assume that the view implementation can handle all kinds of
59 * contexts. Override this method if that is not the case.
60 *
61 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext Controller context which is available inside the view
62 * @return bool TRUE if the view has something useful to display, otherwise FALSE
63 */
64 public function canRender(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
65 {
66 return true;
67 }
68
69 /**
70 * Sets the current controller context
71 *
72 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
73 * @internal
74 */
75 public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
76 {
77 $request = $controllerContext->getRequest();
78 $this->controllerContext = $controllerContext;
79 $this->baseRenderingContext->getTemplatePaths()->fillDefaultsByPackageName($request->getControllerExtensionKey());
80 $this->baseRenderingContext->getTemplatePaths()->setFormat($request->getFormat());
81 if ($this->baseRenderingContext instanceof RenderingContext) {
82 $this->baseRenderingContext->setControllerContext($controllerContext);
83 }
84 }
85
86 /**
87 * @param string $templateName
88 * @internal
89 */
90 public function setTemplate($templateName)
91 {
92 $this->baseRenderingContext->setControllerAction($templateName);
93 }
94
95 /**
96 * Sets the path and name of of the template file. Effectively overrides the
97 * dynamic resolving of a template file.
98 *
99 * @param string $templatePathAndFilename Template file path
100 */
101 public function setTemplatePathAndFilename($templatePathAndFilename)
102 {
103 $this->baseRenderingContext->getTemplatePaths()->setTemplatePathAndFilename($templatePathAndFilename);
104 }
105
106 /**
107 * Set the root path(s) to the templates.
108 * If set, overrides the one determined from $this->templateRootPathPattern
109 *
110 * @param string[] $templateRootPaths Root path(s) to the templates. If set, overrides the one determined from $this->templateRootPathPattern
111 */
112 public function setTemplateRootPaths(array $templateRootPaths)
113 {
114 $this->baseRenderingContext->getTemplatePaths()->setTemplateRootPaths($templateRootPaths);
115 }
116
117 /**
118 * Resolves the template root to be used inside other paths.
119 *
120 * @return string[] Path(s) to template root directory
121 */
122 public function getTemplateRootPaths()
123 {
124 return $this->baseRenderingContext->getTemplatePaths()->getTemplateRootPaths();
125 }
126 /**
127 * Set the root path(s) to the partials.
128 * If set, overrides the one determined from $this->partialRootPathPattern
129 *
130 * @param string[] $partialRootPaths Root paths to the partials. If set, overrides the one determined from $this->partialRootPathPattern
131 */
132 public function setPartialRootPaths(array $partialRootPaths)
133 {
134 $this->baseRenderingContext->getTemplatePaths()->setPartialRootPaths($partialRootPaths);
135 }
136
137 /**
138 * Returns the absolute path to the folder that contains Fluid partial files
139 *
140 * @return string[] Fluid partial root paths
141 * @throws InvalidTemplateResourceException
142 */
143 public function getPartialRootPaths()
144 {
145 return $this->baseRenderingContext->getTemplatePaths()->getPartialRootPaths();
146 }
147
148 /**
149 * Resolves the layout root to be used inside other paths.
150 *
151 * @return string[] Fluid layout root paths
152 * @throws InvalidTemplateResourceException
153 */
154 public function getLayoutRootPaths()
155 {
156 return $this->baseRenderingContext->getTemplatePaths()->getLayoutRootPaths();
157 }
158
159 /**
160 * Set the root path(s) to the layouts.
161 * If set, overrides the one determined from $this->layoutRootPathPattern
162 *
163 * @param string[] $layoutRootPaths Root path to the layouts. If set, overrides the one determined from $this->layoutRootPathPattern
164 */
165 public function setLayoutRootPaths(array $layoutRootPaths)
166 {
167 $this->baseRenderingContext->getTemplatePaths()->setLayoutRootPaths($layoutRootPaths);
168 }
169 }