BeforeFinishersAreExecutedEvent
New in version 15.0 Feature: #111101 - PSR-14 event BeforeFinishersAreExecutedEvent
The event
\TYPO3\
is dispatched once a form was submitted successfully: after the last page
is validated and before the finishers of the form run. A listener can react
to the submission, for example to notify an external system.
The finishers of this submission are in $finishers, in the order they run.
A listener can remove, reorder, or add finishers. This changes only the
current submission, not the form definition. The form runtime is available
in $form, and the finisher context, which every finisher receives,
in $finisher. Variables that a listener adds to the finisher
variable provider of the context are available to the finishers.
Example: Skip the confirmation email when the user declines it
The form newsletter has a field send. If the user
sets it to no, the following listener removes the finisher
Email, which sends the confirmation email. All other finishers
still run:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
use TYPO3\CMS\Form\Domain\Finishers\FinisherInterface;
use TYPO3\CMS\Form\Event\BeforeFinishersAreExecutedEvent;
final readonly class SkipConfirmationEmailListener
{
#[AsEventListener(
identifier: 'my-extension/skip-confirmation-email',
)]
public function __invoke(BeforeFinishersAreExecutedEvent $event): void
{
if ($event->formRuntime->getIdentifier() !== 'newsletterSignup') {
return;
}
$formValues = $event->finisherContext->getFormValues();
if (($formValues['sendConfirmationEmail'] ?? 'yes') !== 'no') {
return;
}
// Remove the email to the sender, keep all other finishers
$event->finishers = array_values(array_filter(
$event->finishers,
static fn(FinisherInterface $finisher): bool =>
!$finisher instanceof AbstractFinisher
|| $finisher->getFinisherIdentifier() !== 'EmailToSender',
));
}
}