[BUGFIX] Fix recursive FLUIDTEMPLATE cObj's that use layoutRootPaths 52/55252/3
authorBenjamin Franzke <bfr@qbus.de>
Tue, 17 Oct 2017 14:53:28 +0000 (16:53 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Wed, 3 Jan 2018 17:54:18 +0000 (18:54 +0100)
FLUIDTEMPLATE variables may contain content elements (e.g. recursive
FLUIDTEMPLATE's) which may instantiate own TemplateViews
(e.g. StandaloneView).
A recursive StandaloneView will statically(!!) cache used TemplatesPaths
in \TYPO3Fluid\Fluid\View\Templates::resolvedFiles.

If StandaloneView is instantiated before, but the fluid layout path is
calculated after inner content objects are being rendering,
the altered statically cached `resolvedFiles` cache is used
and contains invalid layoutRootPaths.

Short term solution:
Defer the initialization of the StandaloneView (which flushes those
buggy caches) until all variables have been processed.

Change-Id: Idf053b3d0f0835a352790e0ed971344d67844bbc
Releases: master, 8.7
Resolves: #79760
Resolves: #82745
Reviewed-on: https://review.typo3.org/55252
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/frontend/Classes/ContentObject/FluidTemplateContentObject.php
typo3/sysext/frontend/Tests/Functional/ContentObject/FluidTemplateContentObjectTest.php

index 862ac1a..92e7a19 100644 (file)
@@ -84,12 +84,14 @@ class FluidTemplateContentObject extends AbstractContentObject
      */
     public function render($conf = [])
     {
-        $parentView = $this->view;
-        $this->initializeStandaloneViewInstance();
-
         if (!is_array($conf)) {
             $conf = [];
         }
+        $variables = $this->getContentObjectVariables($conf);
+        $variables = $this->contentDataProcessor->process($this->cObj, $conf, $variables);
+
+        $parentView = $this->view;
+        $this->initializeStandaloneViewInstance();
 
         $this->setFormat($conf);
         $this->setTemplate($conf);
@@ -97,8 +99,6 @@ class FluidTemplateContentObject extends AbstractContentObject
         $this->setPartialRootPath($conf);
         $this->setExtbaseVariables($conf);
         $this->assignSettings($conf);
-        $variables = $this->getContentObjectVariables($conf);
-        $variables = $this->contentDataProcessor->process($this->cObj, $conf, $variables);
 
         $this->view->assignMultiple($variables);
 
index 01d83a8..8edd8e3 100644 (file)
@@ -21,7 +21,19 @@ use TYPO3\CMS\Frontend\ContentObject\TextContentObject;
  */
 class FluidTemplateContentObjectTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
 {
-    protected $coreExtensionsToLoad = ['fluid'];
+    /**
+     * @var array
+     */
+    protected $coreExtensionsToLoad = [
+        'fluid'
+    ];
+
+    /**
+     * @var array
+     */
+    protected $testExtensionsToLoad = [
+        'typo3/sysext/fluid/Tests/Functional/Fixtures/Extensions/fluid_test',
+    ];
 
     /**
      * @test
@@ -64,4 +76,52 @@ class FluidTemplateContentObjectTest extends \TYPO3\TestingFramework\Core\Functi
 
         $this->assertEquals($expectedResult, $result);
     }
+
+    /**
+     * @test
+     */
+    public function renderWorksWithNestedFluidtemplateWithLayouts()
+    {
+        /** @var $tsfe \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
+        $tsfe = $this->createMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class);
+        $GLOBALS['TSFE'] = $tsfe;
+
+        $configuration = [
+            '10' => 'FLUIDTEMPLATE',
+            '10.' => [
+                'template' => 'TEXT',
+                'template.' => [
+                    'value' => '<f:layout name="BaseLayout"/><f:section name="main"><f:format.raw>{anotherFluidTemplate}</f:format.raw></f:section>'
+                ],
+                'layoutRootPaths.' => [
+                    '0' => 'EXT:fluid_test/Resources/Private/Layouts'
+                ],
+                'variables.' => [
+                    'anotherFluidTemplate' => 'FLUIDTEMPLATE',
+                    'anotherFluidTemplate.' => [
+                        'template' => 'TEXT',
+                        'template.' => [
+                            'value' => '<f:layout name="BaseLayout"/><f:section name="main"></f:section>'
+                        ],
+                        'layoutRootPaths.' => [
+                            '0' => 'EXT:fluid_test/Resources/Private/LayoutOverride/Layouts'
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $expectedResult = 'DefaultLayoutLayoutOverride';
+
+        $contentObjectRenderer = new \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
+        $contentObjectRenderer->setContentObjectClassMap([
+            'FLUIDTEMPLATE' => FluidTemplateContentObject::class,
+            'TEXT' => TextContentObject::class,
+        ]);
+        $fluidTemplateContentObject = new \TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject(
+            $contentObjectRenderer
+        );
+        $result = preg_replace('/\s+/', '', strip_tags($fluidTemplateContentObject->render($configuration)));
+
+        $this->assertEquals($expectedResult, $result);
+    }
 }