Feature: #107568 - PSR-14 Event before renderable is validated
See forge#107568
Description
A new PSR-14 event
\TYPO3\
has been introduced which serves as an improved replacement for the now
removed hook
$GLOBALS
.
The new event is dispatched just right before a renderable is validated.
The event provides the following public properties:
$value
: The submitted value of the renderable$form
: The form runtime object (readonly)Runtime $renderable
: The renderable (readonly)$request
: The current request (readonly)
Example
An example event listener could look like:
use TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent;
class MyEventListener {
#[AsEventListener(
identifier: 'my-extension/before-renderable-is-validated',
)]
public function __invoke(BeforeRenderableIsValidatedEvent $event): void
{
$renderable = $event->renderable;
if ($renderable->getType() !== 'AdvancedPassword') {
return;
}
$elementValue = $event->value;
if ($elementValue['password'] !== $elementValue['confirmation']) {
$processingRule = $renderable->getRootForm()->getProcessingRule($renderable->getIdentifier());
$processingRule->getProcessingMessages()->addError(
GeneralUtility::makeInstance(
Error::class,
GeneralUtility::makeInstance(TranslationService::class)->translate('validation.error.1556283177', null, 'EXT:form/Resources/Private/Language/locallang.xlf'),
1556283177
)
);
}
$event->value = $elementValue['password'];
}
}
Copied!
Impact
With the new PSR-14
Before
, it's now
possible to prevent the deletion of a renderable and to add custom logic
based on the deletion.