From c80b6747d0ef55a033adbc4a18801c4722dae8c9 Mon Sep 17 00:00:00 2001 From: Daniel Lorenz Date: Tue, 20 Dec 2016 12:43:27 +0100 Subject: [PATCH] [BUGFIX] Add missing getTemplatePathAndFilename() in TemplatePaths The StandaloneView getTemplatePathAndFilename() calls a method that the fluid standalone extension doesn't implement anymore, hence the method is added to the Core's TemplatePaths class. Additionally, a lot of type checks are added to ensure that the correct object types are present in all usages. Resolves: #79045 Releases: master Change-Id: I3ec766a29c31d299451f33dd079a56e9a5855c69 Reviewed-on: https://review.typo3.org/51004 Tested-by: TYPO3com Reviewed-by: Nicole Cordes Tested-by: Nicole Cordes Reviewed-by: Markus Klein Tested-by: Markus Klein --- .../Classes/View/AbstractTemplateView.php | 6 ++-- .../fluid/Classes/View/StandaloneView.php | 33 ++++++++++++++++--- .../fluid/Classes/View/TemplatePaths.php | 10 ++++++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php b/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php index d6ab6cbfbcb2..1e427a64195b 100644 --- a/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php +++ b/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php @@ -50,7 +50,7 @@ abstract class AbstractTemplateView extends TemplateView implements \TYPO3\CMS\E if (!$context) { $context = GeneralUtility::makeInstance(ObjectManager::class)->get(RenderingContext::class, $this); } - $this->setRenderingContext($context); + parent::__construct($context); } /** @@ -80,6 +80,8 @@ abstract class AbstractTemplateView extends TemplateView implements \TYPO3\CMS\E $this->controllerContext = $controllerContext; $this->baseRenderingContext->getTemplatePaths()->fillDefaultsByPackageName($request->getControllerExtensionKey()); $this->baseRenderingContext->getTemplatePaths()->setFormat($request->getFormat()); - $this->baseRenderingContext->setControllerContext($controllerContext); + if ($this->baseRenderingContext instanceof RenderingContext) { + $this->baseRenderingContext->setControllerContext($controllerContext); + } } } diff --git a/typo3/sysext/fluid/Classes/View/StandaloneView.php b/typo3/sysext/fluid/Classes/View/StandaloneView.php index 7716b3ae2af0..24dad285e2d9 100644 --- a/typo3/sysext/fluid/Classes/View/StandaloneView.php +++ b/typo3/sysext/fluid/Classes/View/StandaloneView.php @@ -32,6 +32,11 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; */ class StandaloneView extends AbstractTemplateView { + /** + * @var ObjectManager|null + */ + protected $objectManager = null; + /** * Constructor * @@ -64,7 +69,7 @@ class StandaloneView extends AbstractTemplateView $controllerContext->setUriBuilder($uriBuilder); $renderingContext = $this->objectManager->get(RenderingContext::class, $this); $renderingContext->setControllerContext($controllerContext); - $this->setRenderingContext($renderingContext); + parent::__construct($renderingContext); } /** @@ -80,32 +85,45 @@ class StandaloneView extends AbstractTemplateView * * @param string $format * @return void + * @throws \RuntimeException * @api */ public function setFormat($format) { - $this->baseRenderingContext->getControllerContext()->getRequest()->setFormat($format); + if ($this->baseRenderingContext instanceof RenderingContext) { + $this->baseRenderingContext->getControllerContext()->getRequest()->setFormat($format); + } else { + throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251886); + } } /** * Returns the format of the current request (defaults is "html") * * @return string $format + * @throws \RuntimeException * @api */ public function getFormat() { - return $this->baseRenderingContext->getControllerContext()->getRequest()->getFormat(); + if ($this->baseRenderingContext instanceof RenderingContext) { + return $this->baseRenderingContext->getControllerContext()->getRequest()->getFormat(); + } + throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251887); } /** * Returns the current request object * * @return WebRequest + * @throws \RuntimeException */ public function getRequest() { - return $this->baseRenderingContext->getControllerContext()->getRequest(); + if ($this->baseRenderingContext instanceof RenderingContext) { + return $this->baseRenderingContext->getControllerContext()->getRequest(); + } + throw new \RuntimeException('The rendering context must be of type ' . RenderingContext::class, 1482251888); } /** @@ -124,11 +142,16 @@ class StandaloneView extends AbstractTemplateView * Returns the absolute path to a Fluid template file if it was specified with setTemplatePathAndFilename() before * * @return string Fluid template path + * @throws \RuntimeException * @api */ public function getTemplatePathAndFilename() { - return $this->baseRenderingContext->getTemplatePaths()->getTemplatePathAndFilename(); + $templatePaths = $this->baseRenderingContext->getTemplatePaths(); + if ($templatePaths instanceof TemplatePaths) { + return $templatePaths->getTemplatePathAndFilename(); + } + throw new \RuntimeException('The template paths storage must be of type ' . TemplatePaths::class, 1482251889); } /** diff --git a/typo3/sysext/fluid/Classes/View/TemplatePaths.php b/typo3/sysext/fluid/Classes/View/TemplatePaths.php index ac9eae858b49..ec989e14f820 100644 --- a/typo3/sysext/fluid/Classes/View/TemplatePaths.php +++ b/typo3/sysext/fluid/Classes/View/TemplatePaths.php @@ -237,4 +237,14 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths { return parent::getPartialPathAndFilename($partialName); } + + /** + * Get absolute path to template file + * + * @return string Returns the absolute path to a Fluid template file + */ + public function getTemplatePathAndFilename() + { + return $this->templatePathAndFilename; + } } -- 2.20.1