Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expand DataEventListener to account for non-standard File attri… #32

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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