Skip to content

Commit

Permalink
feat: allow non-standard file attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdmlln committed Aug 27, 2024
1 parent 163e9e9 commit 32f5916
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion Classes/Event/Listener/EnrichFileDataEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,39 @@
namespace Remind\Headless\Event\Listener;

use FriendsOfTYPO3\Headless\Event\EnrichFileDataEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class EnrichFileDataEventListener
{
public function __invoke(EnrichFileDataEvent $event): void
{
$originalFile = $event->getOriginal();
$properties = $event->getProperties();
$properties['lazyLoading'] = (bool) $originalFile->getProperty('tx_headless_lazy_loading');
$processingConfiguration = $event->getProcessingConfiguration();

$defaultFields = $processingConfiguration->defaultFieldsByType ?? [];
$imageFields = array_merge($defaultFields, $processingConfiguration->defaultImageFields ?? []);
$videoFields = array_merge($defaultFields, $processingConfiguration->defaultVideoFields ?? []);

$fields = match ($properties['type']) {
'image' => $imageFields,
'video' => $videoFields,
default => $defaultFields,
};

foreach ($fields as $field) {
$as = $field;
if (str_contains($field, ' as ')) {
[$field, $as] = GeneralUtility::trimExplode(' as ', $field, true);
}
if (
$originalFile->hasProperty($field) &&
!array_key_exists($as, $properties)
) {
$properties[$as] = $originalFile->getProperty($field);
}
}

$event->setProperties($properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ lib.assetProcessingConfiguration {
linkResult = 1
properties {
byType = 1
defaultFieldsByType = uidLocal,fileReferenceUid,type,extension,title,description,lazyLoading
defaultImageFields = alternative,link,dimensions
defaultFieldsByType = uidLocal,fileReferenceUid,type,extension,title,description,tx_headless_lazy_loading as lazyLoading
defaultImageFields = alternative,link,dimensions
defaultVideoFields = autoplay
}
}

0 comments on commit 32f5916

Please sign in to comment.