Skip to content

Commit

Permalink
[BUGFIX] match handling of gallery processing with core (#513)
Browse files Browse the repository at this point in the history
- add ability to delay image processing to gallery data processor
resolves #430
  • Loading branch information
twoldanski authored Nov 9, 2022
1 parent edd7828 commit 1c13960
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
8 changes: 7 additions & 1 deletion Classes/DataProcessing/FilesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ protected function processFiles(array $properties = []): ?array

foreach ($this->fileObjects as $key => $fileObject) {
if (isset($this->processorConfiguration['processingConfiguration.']['autogenerate.'])) {
$file = $this->getFileUtility()->processFile($fileObject, $properties, $cropVariant);
$file = $this->getFileUtility()->processFile(
$fileObject,
$properties,
$cropVariant,
(int)($this->processorConfiguration['processingConfiguration.']['delayProcessing'] ?? 0) === 1
);

$targetWidth = (int)($properties['width'] ?: $file['properties']['dimensions']['width']);
$targetHeight = (int)($properties['height'] ?: $file['properties']['dimensions']['height']);

Expand Down
4 changes: 2 additions & 2 deletions Classes/DataProcessing/GalleryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ protected function prepareGalleryData()
$fileObj = $this->fileObjects[$fileKey] ?? null;

if ($fileObj) {
if (($this->equalMediaWidth || $this->equalMediaHeight) && $fileObj['properties']['type'] === 'image') {
$image = $this->getImageService()->getImage($fileObj['properties']['originalUrl'], null, true);
if ($fileObj['properties']['type'] === 'image') {
$image = $this->getImageService()->getImage((string)$fileObj['properties']['fileReferenceUid'], null, true);
$fileObj = $this->getFileUtility()->processFile($image, $this->mediaDimensions[$fileKey] ?? []);

if (isset($this->processorConfiguration['autogenerate.']['retina2x'],
Expand Down
6 changes: 2 additions & 4 deletions Classes/Utility/FileUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ public function __construct(
}

/**
* @param FileInterface $fileReference
* @param array $dimensions
* @param string $cropVariant
* @return array
*/
public function processFile(FileInterface $fileReference, array $dimensions = [], string $cropVariant = 'default'): array
public function processFile(FileInterface $fileReference, array $dimensions = [], string $cropVariant = 'default', bool $delayProcessing = false): array
{
$fileReferenceUid = $fileReference->getUid();
$uidLocal = $fileReference->getProperty('uid_local');
Expand All @@ -107,7 +105,7 @@ public function processFile(FileInterface $fileReference, array $dimensions = []
];

if ($fileRenderer === null && $fileReference->getType() === AbstractFile::FILETYPE_IMAGE) {
if ($fileReference->getMimeType() !== 'image/svg+xml') {
if (!$delayProcessing && $fileReference->getMimeType() !== 'image/svg+xml') {
$fileReference = $this->processImageFile($fileReference, $dimensions, $cropVariant);
}
$publicUrl = $this->imageService->getImageUri($fileReference, true);
Expand Down
3 changes: 3 additions & 0 deletions Configuration/TypoScript/ContentElement/Image.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ tt_content.image {
10 {
references.fieldName = image
as = files
processingConfiguration {
delayProcessing = 1
}
}
20 = FriendsOfTYPO3\Headless\DataProcessing\GalleryProcessor
20 {
Expand Down
3 changes: 3 additions & 0 deletions Configuration/TypoScript/ContentElement/Textmedia.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ tt_content.textmedia {
10 {
references.fieldName = assets
as = files
processingConfiguration {
delayProcessing = 1
}
}
20 = FriendsOfTYPO3\Headless\DataProcessing\GalleryProcessor
20 {
Expand Down
3 changes: 3 additions & 0 deletions Configuration/TypoScript/ContentElement/Textpic.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ tt_content.textpic {
10 {
references.fieldName = image
as = files
processingConfiguration {
delayProcessing = 1
}
}
20 = FriendsOfTYPO3\Headless\DataProcessing\GalleryProcessor
20 {
Expand Down

0 comments on commit 1c13960

Please sign in to comment.