AfterFormDefinitionLoadedEvent
New in version 13.0
The PSR-14 event
\TYPO3\
allows extensions to modify loaded form definitions.
The event is dispatched after
\TYPO3\
has loaded
the definition either from the cache or the filesystem. In latter case, the
event is dispatched after Form
has stored the loaded
definition in cache. This means, it is always possible to modify the cached
version. However, the modified form definition is then overridden by TypoScript,
in case a corresponding
formDefinitionOverrides
exists.
Example
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\LinkHandling\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Form\Mvc\Persistence\Event\AfterFormDefinitionLoadedEvent;
#[AsEventListener(
identifier: 'my-extension/after-form-definition-loaded',
)]
final readonly class MyEventListener
{
public function __invoke(AfterFormDefinitionLoadedEvent $event): void
{
if ($event->getPersistenceIdentifier() === '1:/form_definitions/contact.form.yaml') {
$formDefinition = $event->getFormDefinition();
$formDefinition['label'] = 'Some new label';
$event->setFormDefinition($formDefinition);
}
}
}
New in version 13.0
The PHP attribute \TYPO3\
has been
introduced to tag a PHP class as an event listener. Alternatively, you can also
register an event listener via the Configuration/
file. Have
a look into the section Implementing an event listener in your extension.