[BUGFIX] Fix regression in RenderingContext::__construct w/o View 08/50708/6
authorClaus Due <claus@namelesscoder.net>
Fri, 18 Nov 2016 16:38:24 +0000 (17:38 +0100)
committerAndreas Fernandez <typo3@scripting-base.de>
Fri, 18 Nov 2016 20:30:03 +0000 (21:30 +0100)
This patch fixes a regression after https://review.typo3.org/#/c/50590/
which unfortunately caused some custom implementations
(e.g. static info tables extension) to fail with a PHP fatal error.

Change-Id: I61f7327208e20a973471fbfed02fe83c00d3995c
Resolves: #78746
Releases: master
Reviewed-on: https://review.typo3.org/50708
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Riccardo De Contardi <erredeco@gmail.com>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/fluid/Classes/Core/Rendering/RenderingContext.php

index 7b0554b..09a927e 100644 (file)
@@ -24,10 +24,13 @@ use TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\Expression\LegacyNamespaceExpressionN
 use TYPO3\CMS\Fluid\Core\Variables\CmsVariableProvider;
 use TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperResolver;
 use TYPO3\CMS\Fluid\View\TemplatePaths;
+use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
 use TYPO3Fluid\Fluid\Core\Parser\Configuration;
 use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\CastingExpressionNode;
 use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\MathExpressionNode;
 use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\TernaryExpressionNode;
+use TYPO3Fluid\Fluid\Core\Parser\TemplateParser;
+use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker;
 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
 use TYPO3Fluid\Fluid\View\ViewInterface;
 
@@ -117,12 +120,21 @@ class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
      */
     public function __construct(ViewInterface $view = null)
     {
-        parent::__construct($view);
+        if ($view !== null) {
+            // Note: if $view is received here this indicates internal framework instancing
+            // and it is safe to call the parent constructor. Custom, non-view-providing
+            // usages will only perform the initialisation below (which is sufficient mind you!)
+            parent::__construct($view);
+        } else {
+            // Reproduced partial initialisation from parent::__construct; minus the custom
+            // implementations we attach below.
+            $this->setTemplateParser(new TemplateParser());
+            $this->setTemplateCompiler(new TemplateCompiler());
+            $this->setViewHelperInvoker(new ViewHelperInvoker());
+            $this->setViewHelperVariableContainer(new ViewHelperVariableContainer());
+        }
 
         $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-        if ($view) {
-            $this->view = $view;
-        }
         $this->setTemplatePaths($objectManager->get(TemplatePaths::class));
         $this->setViewHelperResolver($objectManager->get(ViewHelperResolver::class));
         $this->setVariableProvider($objectManager->get(CmsVariableProvider::class));