Skip to content

Commit

Permalink
[BUGFIX] Remove obsolete fields and enable cropping for author images
Browse files Browse the repository at this point in the history
Fixes: #87
Releases: master, 9.1, 9.0, 8.7
  • Loading branch information
benjaminkott committed Jun 25, 2019
1 parent 6155665 commit b31a526
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
9 changes: 9 additions & 0 deletions Classes/AvatarProvider/ImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
40 changes: 18 additions & 22 deletions Configuration/TCA/tx_blog_domain_model_author.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b31a526

Please sign in to comment.