[BUGFIX] Fix wrong stdWrap implementation for paths in FLUIDTEMPLATE 02/44102/5
authorMarkus Klein <markus.klein@typo3.org>
Fri, 16 Oct 2015 10:50:10 +0000 (12:50 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 16 Oct 2015 12:20:04 +0000 (14:20 +0200)
Also adjust the tests to cover more cases.

Resolves: #70788
Releases: master
Change-Id: I60900638689c0f74fa77c624840da394144143ea
Reviewed-on: http://review.typo3.org/44102
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/frontend/Classes/ContentObject/FluidTemplateContentObject.php
typo3/sysext/frontend/Tests/Unit/ContentObject/FluidTemplateContentObjectTest.php

index 098cade..e1b9391 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Frontend\ContentObject;
  */
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 use TYPO3\CMS\Extbase\Service\TypoScriptService;
 use TYPO3\CMS\Fluid\View\StandaloneView;
 
@@ -130,14 +131,7 @@ class FluidTemplateContentObject extends AbstractContentObject
     {
         // Fetch the Fluid template by templateName
         if (!empty($conf['templateName']) && !empty($conf['templateRootPaths.']) && is_array($conf['templateRootPaths.'])) {
-            $templateRootPaths = array();
-            foreach ($conf['templateRootPaths.'] as $key => $path) {
-                if (strpos($key, '.') === false) {
-                    $templateRootPaths[$key] = isset($conf['templateRootPaths.'][$key . '.']) ?
-                            GeneralUtility::getFileAbsFileName($this->cObj->stdWrap($conf['templateRootPaths.'][$key], $conf['templateRootPaths.'][$key . '.'])) :
-                            GeneralUtility::getFileAbsFileName($path);
-                }
-            }
+            $templateRootPaths = $this->applyStandardWrapToFluidPaths($conf['templateRootPaths.']);
             $this->view->setTemplateRootPaths($templateRootPaths);
             $templateName = isset($conf['templateName.']) ? $this->cObj->stdWrap($conf['templateName'], $conf['templateName.']) : $conf['templateName'];
             $this->view->setTemplate($templateName);
@@ -172,13 +166,7 @@ class FluidTemplateContentObject extends AbstractContentObject
             $layoutPaths[] = GeneralUtility::getFileAbsFileName($layoutRootPath);
         }
         if (isset($conf['layoutRootPaths.'])) {
-            foreach ($conf['layoutRootPaths.'] as $key => $path) {
-                if (strpos($key, '.') === false) {
-                    $layoutPaths[$key] = isset($conf['layoutRootPaths.'][$key . '.']) ?
-                        GeneralUtility::getFileAbsFileName($this->cObj->stdWrap($conf['layoutRootPaths.'][$key], $conf['layoutRootPaths.'][$key . '.'])) :
-                        GeneralUtility::getFileAbsFileName($path);
-                }
-            }
+            $layoutPaths = array_replace($layoutPaths, $this->applyStandardWrapToFluidPaths($conf['layoutRootPaths.']));
         }
         if (!empty($layoutPaths)) {
             $this->view->setLayoutRootPaths($layoutPaths);
@@ -201,13 +189,7 @@ class FluidTemplateContentObject extends AbstractContentObject
             $partialPaths[] = GeneralUtility::getFileAbsFileName($partialRootPath);
         }
         if (isset($conf['partialRootPaths.'])) {
-            foreach ($conf['partialRootPaths.'] as $key => $path) {
-                if (strpos($key, '.') === false) {
-                    $partialPaths[$key] = isset($conf['partialRootPaths.'][$key . '.']) ?
-                        GeneralUtility::getFileAbsFileName($this->cObj->stdWrap($conf['partialRootPaths.'][$key], $conf['partialRootPaths.'][$key . '.'])) :
-                        GeneralUtility::getFileAbsFileName($path);
-                }
-            }
+            $partialPaths = array_replace($partialPaths, $this->applyStandardWrapToFluidPaths($conf['partialRootPaths.']));
         }
         if (!empty($partialPaths)) {
             $this->view->setPartialRootPaths($partialPaths);
@@ -327,4 +309,28 @@ class FluidTemplateContentObject extends AbstractContentObject
         }
         return $content;
     }
+
+    /**
+     * Applies stdWrap on Fluid path definitions
+     *
+     * @param array $paths
+     *
+     * @return array
+     */
+    protected function applyStandardWrapToFluidPaths(array $paths)
+    {
+        $finalPaths = [];
+        foreach ($paths as $key => $path) {
+            if (StringUtility::endsWith($key, '.')) {
+                if (isset($paths[substr($key, 0, -1)])) {
+                    continue;
+                }
+                $path = $this->cObj->stdWrap('', $path);
+            } elseif (isset($paths[$key . '.'])) {
+                $path = $this->cObj->stdWrap($path, $paths[$key . '.']);
+            }
+            $finalPaths[$key] = GeneralUtility::getFileAbsFileName($path);
+        }
+        return $finalPaths;
+    }
 }
index 7765d76..d00b0c2 100644 (file)
@@ -151,22 +151,21 @@ class FluidTemplateContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $this->contentObjectRenderer
             ->expects($this->at(0))
             ->method('stdWrap')
-            ->with('FILE', array('file' => 'dummyPath5/'));
+            ->with('dummyPath', array('wrap' => '|5/'));
         $this->contentObjectRenderer
             ->expects($this->at(1))
             ->method('stdWrap')
-            ->with('FILE', array('file' => 'dummyPath25/'));
+            ->with('', array('field' => 'someField'));
         $this->subject->render(array(
                 'templateName' => 'foobar',
                 'templateRootPaths.' => array(
-                    10 => 'FILE',
+                    10 => 'dummyPath',
                     '10.' => array(
-                        'file' => 'dummyPath5/',
+                        'wrap' => '|5/',
                     ),
                     15 => 'dummyPath6/',
-                    25 => 'FILE',
                     '25.' => array(
-                        'file' => 'dummyPath25/',
+                        'field' => 'someField',
                     ),
                 )
             )