[BUGFIX] Fix dynamic variable name parts in Fluid 41/51841/3
authorHelmut Hummel <typo3@helhum.io>
Fri, 24 Feb 2017 19:23:24 +0000 (20:23 +0100)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Sun, 26 Feb 2017 06:15:59 +0000 (07:15 +0100)
The dynamic variable syntax does currently work in Fluid standalone,
but not with the variable provider used for TYPO3 CMS (as promised)

To fix this, we copy the necessary code to the CMS variable provider
as it is only a few lines.

Cover that with tests and apply it in the image cropper UI as one example.

Resolves: #79997
Releases: master
Change-Id: I3a811b0d496b12191d2ccbaa9c07525f4cf8f340
Reviewed-on: https://review.typo3.org/51841
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anders Kostending <aha@systime.dk>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/backend/Resources/Private/Templates/ImageManipulation/ImageManipulationElement.html
typo3/sysext/fluid/Classes/Core/Variables/CmsVariableProvider.php
typo3/sysext/fluid/Tests/Unit/Core/Variables/CmsVariableProviderTest.php

index 9f21743..1644a76 100644 (file)
@@ -32,7 +32,7 @@
                                                <div class="col-xs-6 col-sm-4 col-md-3 media-gallery__item">
                                                        <p>
                                                                <b><f:translate id="{cropVariant.title}" default="{cropVariant.title}" /></b><br/>
-                                                               <f:translate id="LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.aspect-ratio"/>: {cropVariant.selectedRatioTitle}
+                                                               <f:translate id="LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.aspect-ratio"/>: <f:translate id="{cropVariant.allowedAspectRatios.{cropVariant.selectedRatio}.title}" default="{cropVariant.allowedAspectRatios.{cropVariant.selectedRatio}.title}" />
                                                        </p>
                                                        <div class="t3js-image-manipulation-preview media-object"
                                                                 data-preview-height="150"
index 2301791..1f005c9 100644 (file)
@@ -32,6 +32,23 @@ class CmsVariableProvider extends \TYPO3Fluid\Fluid\Core\Variables\StandardVaria
      */
     public function getByPath($path, array $accessors = [])
     {
+        $path = $this->resolveSubVariableReferences($path);
         return \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($this->variables, $path);
     }
+
+    /**
+     * @param string $propertyPath
+     * @return string
+     */
+    protected function resolveSubVariableReferences($propertyPath)
+    {
+        if (strpos($propertyPath, '{') !== false) {
+            preg_match_all('/(\{.*\})/', $propertyPath, $matches);
+            foreach ($matches[1] as $match) {
+                $subPropertyPath = substr($match, 1, -1);
+                $propertyPath = str_replace($match, $this->getByPath($subPropertyPath), $propertyPath);
+            }
+        }
+        return $propertyPath;
+    }
 }
index 5169a2d..1e453cf 100644 (file)
@@ -29,4 +29,21 @@ class CmsVariableProviderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTest
         $instance->setSource(['foo' => 'bar']);
         $this->assertEquals('bar', $instance->getByPath('foo'));
     }
+
+    /**
+     * @test
+     */
+    public function dynamicAccessWorks()
+    {
+        $instance = new CmsVariableProvider();
+        $instance->setSource(
+            [
+                'foo' => [
+                    'hello' => 'world',
+                ],
+                'key' => 'hello'
+            ]
+        );
+        $this->assertEquals('world', $instance->getByPath('foo.{key}'));
+    }
 }