From b31a5268e03a95a1083b3fceea7a2613447256b1 Mon Sep 17 00:00:00 2001 From: Benjamin Kott Date: Tue, 25 Jun 2019 21:25:44 +0200 Subject: [PATCH] [BUGFIX] Remove obsolete fields and enable cropping for author images Fixes: #87 Releases: master, 9.1, 9.0, 8.7 --- Classes/AvatarProvider/ImageProvider.php | 9 +++++ .../TCA/tx_blog_domain_model_author.php | 40 +++++++++---------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Classes/AvatarProvider/ImageProvider.php b/Classes/AvatarProvider/ImageProvider.php index 1b499977..852747ca 100644 --- a/Classes/AvatarProvider/ImageProvider.php +++ b/Classes/AvatarProvider/ImageProvider.php @@ -11,6 +11,7 @@ use T3G\AgencyPack\Blog\AvatarProviderInterface; use T3G\AgencyPack\Blog\Domain\Model\Author; +use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Domain\Model\FileReference; @@ -55,11 +56,19 @@ public function getAvatarUrl(Author $author) $imageService = $objectManager->get(ImageService::class); $image = $imageService->getImage('', $image, false); + + if ($image->hasProperty('crop') && $image->getProperty('crop')) { + $cropString = $image->getProperty('crop'); + } + $cropVariantCollection = CropVariantCollection::create((string)$cropString); + $cropArea = $cropVariantCollection->getCropArea('default'); + $processingInstructions = [ 'width' => $size . 'c', 'height' => $size, 'minWidth' => $size, 'minHeight' => $size, + 'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image), ]; $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions); return $imageService->getImageUri($processedImage); diff --git a/Configuration/TCA/tx_blog_domain_model_author.php b/Configuration/TCA/tx_blog_domain_model_author.php index a2735e21..90e09b87 100644 --- a/Configuration/TCA/tx_blog_domain_model_author.php +++ b/Configuration/TCA/tx_blog_domain_model_author.php @@ -98,31 +98,27 @@ 'exclude' => 0, 'label' => $ll . 'tx_blog_domain_model_author.image', 'displayCond' => 'FIELD:avatar_provider:=:T3G\AgencyPack\Blog\AvatarProvider\ImageProvider', - 'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', [ - 'appearance' => [ - 'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference', - ], - 'maxitems' => 1, - // custom configuration for displaying fields in the overlay/reference table - // to use the imageoverlayPalette instead of the basicoverlayPalette - 'foreign_match_fields' => [ - 'fieldname' => 'image', - 'tablenames' => 'tx_blog_domain_model_author', - 'table_local' => 'sys_file', - ], - 'foreign_types' => [ - '0' => [ - 'showitem' => ' - --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette, - --palette--;;filePalette', + 'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig( + 'image', + [ + 'appearance' => [ + 'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference' ], - \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [ - 'showitem' => ' - --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette, - --palette--;;filePalette', + 'overrideChildTca' => [ + 'types' => [ + \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [ + 'showitem' => ' + crop, + --palette--;;filePalette + ' + ], + ], ], + 'minitems' => 0, + 'maxitems' => 1, ], - ], $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), + $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] + ), ], 'title' => [ 'exclude' => 0,