Feature: #102865 - PSR-14 event for modifying loaded form definition
See forge#102865
Description
A new PSR-14 event \TYPO3\
has been introduced which allows extensions to modify loaded form definitions.
The event is being dispatched after Form
has loaded
the definition from either the cache or the filesystem. In latter case, the
event is dispatched after Form
has stored the loaded
definition in cache. This means, it's always possible to modify the cached
version. However, the modified form definition is then overridden by TypoScript,
in case a corresponding form
exists.
The event features the following methods:
get
- Returns the loaded form definitionForm Definition () set
- Allows to modify the loaded form definitionForm Definition () get
- Returns the persistence identifier, used to load the definitionPersistence Identifier () get
- Returns the calculated cache keyCache Key ()
Example
The event listener class, using the PHP attribute #
for
registration:
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Form\Mvc\Persistence\Event\AfterFormDefinitionLoadedEvent;
final class AfterFormDefinitionLoadedEventListener
{
#[AsEventListener]
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);
}
}
}
Impact
Using the new PSR-14 event, it's now possible to fully modify any loaded form definition, before being overridden by TypoScript.