BeforeFormValueIsRenderedEvent
New in version 15.0 Feature: #109836 - PSR-14 event before form value is rendered
The event
\TYPO3\
is dispatched before the value of a single form element is rendered, for
example on the summary page or in an email. A listener can change the
data that is passed to Fluid in $data, such as the processed, and
add keys for custom templates. The form element and the form runtime are
available in $element and $form.
Example: Show "Yes" or "No" for a checkbox on the summary page
A checkbox shows its raw value on the summary page and in emails. The
following listener sets the processed of every element of type
Checkbox to "Yes" or "No":
EXT:my_extension/Classes/EventListener/CheckboxYesNoListener.php
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Form\Event\BeforeFormValueIsRenderedEvent;
final readonly class CheckboxYesNoListener
{
#[AsEventListener(
identifier: 'my-extension/checkbox-yes-no',
)]
public function __invoke(BeforeFormValueIsRenderedEvent $event): void
{
if ($event->element->getType() !== 'Checkbox') {
return;
}
// Show "Yes" or "No" in the summary page and in the emails
$event->data['processedValue'] = ($event->data['value'] ?? false)
? 'Yes'
: 'No';
}
}