[FEATURE] Add cropVariant support to typoscript rendering of images 53/51753/6
authorFrans Saris <franssaris@gmail.com>
Sun, 19 Feb 2017 10:46:03 +0000 (11:46 +0100)
committerHelmut Hummel <typo3@helhum.io>
Thu, 23 Feb 2017 09:58:49 +0000 (10:58 +0100)
The introduction of the new crop variants #75880 broke the handling of
cropped images when using typoscript to render file(reference)'s

This patch fixes the rendering of cropped images and introduces the new
cropVariant option to the typoscript object IMG_RESOURCE

Releated: #75880
Resolves: #79883
Releases: master
Change-Id: Icba77d76c6914d48dcc57d7e8c48471ed27c44b3
Reviewed-on: https://review.typo3.org/51753
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Johannes Goslar <jogo@kronberger-spiele.de>
Reviewed-by: Christer V <cvi@systime.dk>
Tested-by: Christer V <cvi@systime.dk>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
Tested-by: Helmut Hummel <typo3@helhum.io>
typo3/sysext/core/Documentation/Changelog/master/Feature-79883-AddCropVariantSupportToTyposcriptRenderingOfImages.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

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 (file)
index 0000000..b2d0f2d
--- /dev/null
@@ -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
index 9beda03..cdaf656 100644 (file)
@@ -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.