AfterFormDefinitionLoadedEvent

New in version 13.0

The PSR-14 event \TYPO3\CMS\Form\Mvc\Persistence\Event\AfterFormDefinitionLoadedEvent allows extensions to modify loaded form definitions.

The event is dispatched after \TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager has loaded the definition either from the cache or the filesystem. In latter case, the event is dispatched after FormPersistenceManager 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

EXT:my_extension/Classes/LinkHandling/EventListener/MyEventListener.php
<?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);
        }
    }
}
Copied!

New in version 13.0

API

class AfterFormDefinitionLoadedEvent
Fully qualified name
\TYPO3\CMS\Form\Mvc\Persistence\Event\AfterFormDefinitionLoadedEvent

Listeners are able to modify the loaded form definition

getFormDefinition ( )
Returns
array
setFormDefinition ( array $formDefinition)
param $formDefinition

the formDefinition

getPersistenceIdentifier ( )
Returns
string
getCacheKey ( )
Returns
string