diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php index b88dad895907786793a84ce15234bd9e9befcc9d..0d871ceb1e2c45709b53e65d6d873f13877cb414 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php @@ -119,7 +119,7 @@ final 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'); @@ -159,6 +159,12 @@ final 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 253f8dc684e21f6216b13670ef82fc59df9b9cb5..215908e9dbd38bd2e3a70ae2532a6035a44708e4 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php @@ -93,7 +93,7 @@ final 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'); @@ -135,6 +135,11 @@ final 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 fe6da45f956f8c6a7fe1ccc97fa9b18b5b1c763e..f957d9c63fb63ecb632478797a2535ef0e12f5a2 100644 --- a/typo3/sysext/fluid/Tests/Functional/ViewHelpers/ImageViewHelperTest.php +++ b/typo3/sysext/fluid/Tests/Functional/ViewHelpers/ImageViewHelperTest.php @@ -61,6 +61,10 @@ final 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="" />$@',