Feature: #109811 - PSR-14 event AfterFormStateInitializedEvent 

See forge#109811

Description 

A new PSR-14 event \TYPO3\CMS\Form\Event\AfterFormStateInitializedEvent has been introduced. It serves as an improved replacement for the now removed hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterFormStateInitialized'] .

The new event is dispatched by FormRuntime after the FormState has been restored from the request. At this point both the form state (submitted values) and the static form definition are available, which makes it particularly suitable for enriching components that need runtime data (e.g. configuring property mapping for file uploads).

The event provides the following public properties:

  • $formRuntime : The form runtime object (read-only).
  • $request : The current request (read-only).

Example 

An example event listener could look like this:

EXT:my_extension/Classes/EventListener/MyAfterFormStateInitializedEventListener.php
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Form\Event\AfterFormStateInitializedEvent;

#[AsEventListener(identifier: 'my-extension/after-form-state-initialized')]
final readonly class MyAfterFormStateInitializedEventListener
{
    public function __invoke(AfterFormStateInitializedEvent $event): void
    {
        // Access $event->formRuntime->getFormState() here
    }
}
Copied!

Impact 

With the new AfterFormStateInitializedEvent , it is now possible to react to the form state being fully initialized using the standard PSR-14 event listener mechanism.