Events you can listen to
The PSR-14 events EXT: dispatches, with their signatures and
caveats, are listed in Reference: Events. This page shows how to register
a listener.
Listener registration
The # attribute is the TYPO3 v14 way; no YAML is
needed. The example adds a signed CDN URL to every file in the response:
<?php
declare(strict_types=1);
namespace Vendor\MyExt\EventListener;
use FriendsOfTYPO3\Headless\Event\EnrichFileDataEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use Vendor\MyExt\Service\CdnSigner;
#[AsEventListener(identifier: 'myext/file/signed-cdn-url')]
final readonly class AddSignedCdnUrl
{
public function __construct(private CdnSigner $cdn) {}
public function __invoke(EnrichFileDataEvent $event): void
{
$publicUrl = $event->getProcessed()->getPublicUrl();
if ($publicUrl === null) {
return;
}
$props = $event->getProperties();
$props['signedUrl'] = $this->cdn->sign($publicUrl);
$event->setProperties($props);
}
}
Copied!
The file URL (url/public) is added to the payload only after the
event, so read it from the processed file.
get returns
null when the file has no public URL.
Alternatively, register the listener via a Services. tag:
# Configuration/Services.yaml
services:
Vendor\MyExt\EventListener\AddSignedCdnUrl:
tags:
- name: event.listener
identifier: 'myext/file/signed-cdn-url'
event: FriendsOfTYPO3\Headless\Event\EnrichFileDataEvent
Copied!
The container is compiled: run bin/ after adding or
changing a listener.