Skip to content

Commit

Permalink
feat: expand DataEventListener to account for non-standard File attri…
Browse files Browse the repository at this point in the history
…butes
  • Loading branch information
KonstantCode committed Jun 12, 2024
1 parent 2720256 commit 3531a02
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Classes/Event/Listener/EnrichFileDataEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,28 @@ class EnrichFileDataEventListener
public function __invoke(EnrichFileDataEvent $event): void
{
$originalFile = $event->getOriginal();
$processedFile = $event->getProcessed();
$properties = $event->getProperties();
$processingConfiguration = $event->getProcessingConfiguration();

// class ProcessingConfiguration always inserts arrays for these defaultFields, so the following checks shouldnt be necessary, but check anyway
$defaultFieldsByType = $processingConfiguration->defaultFieldsByType ?? [];
$defaultImageFields = array_merge($defaultFieldsByType, $processingConfiguration->defaultImageFields ?? []);
$defaultVideoFields = array_merge($defaultFieldsByType, $processingConfiguration->defaultVideoFields ?? []);

$defaultFields = match ($properties['type']) {
'image' => $defaultImageFields,
'video' => $defaultVideoFields,
default => $defaultFieldsByType,
};

// processedFile has to be used here instead of originalFile, otherwise pre processed attributes (like extension = svg) get readded
foreach ($defaultFields as $field) {
if ($processedFile->hasProperty($field) && !isset($properties[$field])) {
$properties[$field] = $processedFile->getProperty($field);
}
}

$properties['lazyLoading'] = (bool) $originalFile->getProperty('tx_headless_lazy_loading') ?? true;
$event->setProperties($properties);
}
Expand Down

0 comments on commit 3531a02

Please sign in to comment.