diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php index 3e952da407ad11f48ba0587c7809db5aef8d67e2..a4155b37e236e75d719a7e0311504bcbf2935bbd 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php @@ -120,7 +120,7 @@ class ImageViewHelper extends AbstractTagBasedViewHelper $this->registerArgument('src', 'string', 'a path to a file, a combined FAL identifier or an uid (int). If $treatIdAsReference is set, the integer is considered the uid of the sys_file_reference record. If you already got a FAL object, consider using the $image parameter instead', false, ''); $this->registerArgument('treatIdAsReference', 'bool', 'given src argument is a sys_file_reference record', false, false); $this->registerArgument('image', 'object', 'a FAL object (\\TYPO3\\CMS\\Core\\Resource\\File or \\TYPO3\\CMS\\Core\\Resource\\FileReference)'); - $this->registerArgument('crop', 'string|bool', 'overrule cropping of image (setting to FALSE disables the cropping set in FileReference)'); + $this->registerArgument('crop', 'string|bool|array', 'overrule cropping of image (setting to FALSE disables the cropping set in FileReference)'); $this->registerArgument('cropVariant', 'string', 'select a cropping variant, in case multiple croppings have been specified or stored in FileReference', false, 'default'); $this->registerArgument('fileExtension', 'string', 'Custom file extension to use'); @@ -158,6 +158,12 @@ class ImageViewHelper extends AbstractTagBasedViewHelper if ($cropString === null && $image->hasProperty('crop') && $image->getProperty('crop')) { $cropString = $image->getProperty('crop'); } + + // CropVariantCollection needs a string, but this VH could also receive an array + if (is_array($cropString)) { + $cropString = json_encode($cropString); + } + $cropVariantCollection = CropVariantCollection::create((string)$cropString); $cropVariant = $this->arguments['cropVariant'] ?: 'default'; $cropArea = $cropVariantCollection->getCropArea($cropVariant); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php index 0f047122a7117bf37ed900a8650d568f39b96c56..4710d24110deb2538ecce8edc4864ff4f4d0a756 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php @@ -94,7 +94,7 @@ class ImageViewHelper extends AbstractViewHelper $this->registerArgument('src', 'string', 'src', false, ''); $this->registerArgument('treatIdAsReference', 'bool', 'given src argument is a sys_file_reference record', false, false); $this->registerArgument('image', 'object', 'image'); - $this->registerArgument('crop', 'string|bool', 'overrule cropping of image (setting to FALSE disables the cropping set in FileReference)'); + $this->registerArgument('crop', 'string|bool|array', 'overrule cropping of image (setting to FALSE disables the cropping set in FileReference)'); $this->registerArgument('cropVariant', 'string', 'select a cropping variant, in case multiple croppings have been specified or stored in FileReference', false, 'default'); $this->registerArgument('fileExtension', 'string', 'Custom file extension to use'); @@ -140,6 +140,11 @@ class ImageViewHelper extends AbstractViewHelper $cropString = $image->getProperty('crop'); } + // CropVariantCollection needs a string, but this VH could also receive an array + if (is_array($cropString)) { + $cropString = json_encode($cropString); + } + $cropVariantCollection = CropVariantCollection::create((string)$cropString); $cropVariant = $arguments['cropVariant'] ?: 'default'; $cropArea = $cropVariantCollection->getCropArea($cropVariant); diff --git a/typo3/sysext/fluid/Tests/Functional/ViewHelpers/ImageViewHelperTest.php b/typo3/sysext/fluid/Tests/Functional/ViewHelpers/ImageViewHelperTest.php index 900de50a798b96c8011afa7b7d34724f9b483586..6a4aa197ffb97e3a4055b11abff49e02c49d21cd 100644 --- a/typo3/sysext/fluid/Tests/Functional/ViewHelpers/ImageViewHelperTest.php +++ b/typo3/sysext/fluid/Tests/Functional/ViewHelpers/ImageViewHelperTest.php @@ -60,6 +60,10 @@ class ImageViewHelperTest extends FunctionalTestCase '<f:image src="EXT:fluid/Tests/Functional/Fixtures/ViewHelpers/ImageViewHelperTest.jpg" width="300" height="500" crop="null" />', '@^<img src="typo3temp/assets/_processed_/b/3/csm_ImageViewHelperTest_.*\.jpg" width="300" height="500" alt="" />$@', ], + 'crop as array' => [ + '<f:image src="EXT:fluid/Tests/Functional/Fixtures/ViewHelpers/ImageViewHelperTest.jpg" width="300" height="500" crop="{\'x\': 200, \'y\': 200, \'width\': 200, \'height\': 200}" />', + '@^<img src="typo3temp/assets/_processed_/b/3/csm_ImageViewHelperTest_.*\.jpg" width="300" height="500" alt="" />$@', + ], 'jpg file extension' => [ '<f:image src="EXT:fluid/Tests/Functional/Fixtures/ViewHelpers/ImageViewHelperTest.jpg" width="300" height="500" crop="null" fileExtension="jpg" />', '@^<img src="typo3temp/assets/_processed_/b/3/csm_ImageViewHelperTest_.*\.jpg" width="300" height="500" alt="" />$@',