Feature: #111101 - PSR-14 event BeforeFinishersAreExecutedEvent 

See forge#111101

Description 

A new PSR-14 event \TYPO3\CMS\Form\Event\BeforeFinishersAreExecutedEvent has been introduced. It is dispatched by FormRuntime once a form has been submitted successfully, after the last page has been validated and before the finishers of the form are executed.

The event provides the following public properties:

  • $finishers : The finishers that will be executed for this submission, in their order of execution. Listeners may remove, reorder or add finishers. The form definition itself is not modified.
  • $formRuntime : The form runtime object (read-only).
  • $finisherContext : The finisher context passed to every finisher (read-only). Variables added to its finisher variable provider are available to the finishers.

Example 

For the form with the identifier newsletterSignup , a listener can skip the built-in EmailFinisher when the submitted form contains a sendConfirmationEmail field set to no :

EXT:my_extension/Classes/EventListener/MyBeforeFinishersAreExecutedEventListener.php
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Form\Domain\Finishers\EmailFinisher;
use TYPO3\CMS\Form\Event\BeforeFinishersAreExecutedEvent;

#[AsEventListener(identifier: 'my-extension/before-finishers-are-executed')]
final readonly class MyBeforeFinishersAreExecutedEventListener
{
    public function __invoke(BeforeFinishersAreExecutedEvent $event): void
    {
        if ($event->formRuntime->getIdentifier() !== 'newsletterSignup') {
            return;
        }

        $formValues = $event->finisherContext->getFormValues();
        if (($formValues['sendConfirmationEmail'] ?? 'yes') !== 'no') {
            return;
        }

        foreach ($event->finishers as $index => $finisher) {
            if (!$finisher instanceof EmailFinisher) {
                continue;
            }

            unset($event->finishers[$index]);
            $event->finishers = array_values($event->finishers);
            return;
        }
    }
}
Copied!

Impact 

With the new BeforeFinishersAreExecutedEvent , it is now possible to react to a successfully submitted form, for example to notify an external system, and to adjust the finishers executed for a single submission using the standard PSR-14 event listener mechanism.