[BUGFIX] Add missing getTemplatePathAndFilename() in TemplatePaths
[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 TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21 use TYPO3Fluid\Fluid\View\TemplateView;
22
23 /**
24 * Abstract Fluid Template View.
25 *
26 * Contains the fundamental methods which any Fluid based template view needs.
27 */
28 abstract class AbstractTemplateView extends TemplateView implements \TYPO3\CMS\Extbase\Mvc\View\ViewInterface
29 {
30 /**
31 * @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
32 */
33 protected $controllerContext;
34
35 /**
36 * Initializes this view.
37 *
38 * @return void
39 * @api
40 */
41 public function initializeView()
42 {
43 }
44
45 /**
46 * @param RenderingContextInterface $context
47 */
48 public function __construct(RenderingContextInterface $context = null)
49 {
50 if (!$context) {
51 $context = GeneralUtility::makeInstance(ObjectManager::class)->get(RenderingContext::class, $this);
52 }
53 parent::__construct($context);
54 }
55
56 /**
57 * Tells if the view implementation can render the view for the given context.
58 *
59 * By default we assume that the view implementation can handle all kinds of
60 * contexts. Override this method if that is not the case.
61 *
62 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext Controller context which is available inside the view
63 * @return bool TRUE if the view has something useful to display, otherwise FALSE
64 * @api
65 */
66 public function canRender(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
67 {
68 return true;
69 }
70
71 /**
72 * Sets the current controller context
73 *
74 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
75 * @return void
76 */
77 public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext)
78 {
79 $request = $controllerContext->getRequest();
80 $this->controllerContext = $controllerContext;
81 $this->baseRenderingContext->getTemplatePaths()->fillDefaultsByPackageName($request->getControllerExtensionKey());
82 $this->baseRenderingContext->getTemplatePaths()->setFormat($request->getFormat());
83 if ($this->baseRenderingContext instanceof RenderingContext) {
84 $this->baseRenderingContext->setControllerContext($controllerContext);
85 }
86 }
87 }