Feature: #111101 - PSR-14 event BeforeFinishersAreExecutedEvent
See forge#111101
Description
A new PSR-14 event
\TYPO3\ has been
introduced. It is dispatched by
Form 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.$form: The form runtime object (read-only).Runtime $finisher: The finisher context passed to every finisher (read-only). Variables added to its finisher variable provider are available to the finishers.Context
Example
For the form with the identifier
newsletter, a listener can skip
the built-in
Email when the submitted form contains a
send field set to
no
:
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;
}
}
}
Impact
With the new
Before, 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.