From b534440e8bd789a1b1f3e84e2e173262094fa836 Mon Sep 17 00:00:00 2001 From: Helmut Hummel <typo3@helhum.io> Date: Fri, 24 Feb 2017 20:23:24 +0100 Subject: [PATCH] [BUGFIX] Fix dynamic variable name parts in Fluid 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> --- .../ImageManipulationElement.html | 2 +- .../Core/Variables/CmsVariableProvider.php | 17 +++++++++++++++++ .../Core/Variables/CmsVariableProviderTest.php | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/typo3/sysext/backend/Resources/Private/Templates/ImageManipulation/ImageManipulationElement.html b/typo3/sysext/backend/Resources/Private/Templates/ImageManipulation/ImageManipulationElement.html index 9f217438b161..1644a76150cf 100644 --- a/typo3/sysext/backend/Resources/Private/Templates/ImageManipulation/ImageManipulationElement.html +++ b/typo3/sysext/backend/Resources/Private/Templates/ImageManipulation/ImageManipulationElement.html @@ -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" diff --git a/typo3/sysext/fluid/Classes/Core/Variables/CmsVariableProvider.php b/typo3/sysext/fluid/Classes/Core/Variables/CmsVariableProvider.php index 2301791b9af0..1f005c9909b4 100644 --- a/typo3/sysext/fluid/Classes/Core/Variables/CmsVariableProvider.php +++ b/typo3/sysext/fluid/Classes/Core/Variables/CmsVariableProvider.php @@ -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; + } } diff --git a/typo3/sysext/fluid/Tests/Unit/Core/Variables/CmsVariableProviderTest.php b/typo3/sysext/fluid/Tests/Unit/Core/Variables/CmsVariableProviderTest.php index 5169a2d11e41..1e453cfb4487 100644 --- a/typo3/sysext/fluid/Tests/Unit/Core/Variables/CmsVariableProviderTest.php +++ b/typo3/sysext/fluid/Tests/Unit/Core/Variables/CmsVariableProviderTest.php @@ -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}')); + } } -- GitLab