diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-79883-AddCropVariantSupportToTyposcriptRenderingOfImages.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-79883-AddCropVariantSupportToTyposcriptRenderingOfImages.rst new file mode 100644 index 0000000000000000000000000000000000000000..b2d0f2dcdd02f229118090e051494005e120898e --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-79883-AddCropVariantSupportToTyposcriptRenderingOfImages.rst @@ -0,0 +1,34 @@ +.. include:: ../../Includes.txt + +=========================================================================== +Feature: #79883 - Add cropVariant support to typoscript rendering of images +=========================================================================== + +See :issue:`79883` + +Description +=========== + +The introduction of the new crop variants :issue:`75880` broke the handling of +cropped images when using typoscript to render file(reference)'s. This feature +fixes this and introduces a new TypoScript option to use a different cropVariant. + +To use a different `cropVariant` as `default` you can provide the `cropVariant` +name now in your TypoScript configuration. If :ts:`cropVariant` isn't provided +the `default` variant will be used. + +.. code-block:: typoscript + + # Use specific cropVariant for the images + tt_content.image.20.1.file.cropVariant = mobile + + + +Impact +====== + +If multiple cropVariants are available (see :issue:`75880`) you can now configure +which variant to use with the :ts:`cropVariant` option of :ts:`imgResource`. + + +.. index:: FAL, Frontend, TypoScript \ No newline at end of file diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php index 9beda03eb6cc38de5a2c3fc1ea028f688a5a0189..cdaf656c7086c8f4e0397d8ba3127a57ff529b22 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php @@ -26,6 +26,7 @@ use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer; use TYPO3\CMS\Core\FrontendEditing\FrontendEditingController; use TYPO3\CMS\Core\Html\HtmlParser; +use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection; use TYPO3\CMS\Core\LinkHandling\LinkService; use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Core\Mail\MailMessage; @@ -5035,7 +5036,7 @@ class ContentObjectRenderer } elseif ($file instanceof FileReference) { $fileObject = $file->getOriginalFile(); if (!isset($fileArray['crop'])) { - $fileArray['crop'] = $file->getProperty('crop'); + $fileArray['crop'] = $this->getCropArea($file, $fileArray['cropVariant'] ?: 'default'); } } else { try { @@ -5052,7 +5053,7 @@ class ContentObjectRenderer $fileReference = $this->getResourceFactory()->getFileReferenceObject($file); $fileObject = $fileReference->getOriginalFile(); if (!isset($fileArray['crop'])) { - $fileArray['crop'] = $fileReference->getProperty('crop'); + $fileArray['crop'] = $this->getCropArea($fileReference, $fileArray['cropVariant'] ?: 'default'); } } else { $fileObject = $this->getResourceFactory()->getFileObject($file); @@ -5155,6 +5156,20 @@ class ContentObjectRenderer return $imageResource; } + /** + * @param FileReference $fileReference + * @param string $cropVariant + * @return null|\TYPO3\CMS\Core\Imaging\ImageManipulation\Area + */ + protected function getCropArea(FileReference $fileReference, string $cropVariant) + { + $cropVariantCollection = CropVariantCollection::create( + (string)$fileReference->getProperty('crop') + ); + $cropArea = $cropVariantCollection->getCropArea($cropVariant); + return $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($fileReference); + } + /*********************************************** * * Data retrieval etc.