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 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\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, you can also register an event listener via the Configuration/Services.yaml file. Have a look into the section Implementing an event listener in your extension.

API

class TYPO3\CMS\Form\Mvc\Persistence\Event\AfterFormDefinitionLoadedEvent

Listeners are able to modify the loaded form definition

getFormDefinition()
Return type

array

setFormDefinition(array $formDefinition)
Parameters
  • $formDefinition (array) -- the formDefinition

getPersistenceIdentifier()
Return type

string

getCacheKey()
Return type

string