Skip to content

Commit eb29f24

Browse files
[FEATURE] Add new form event BeforeRenderableIsValidatedEvent (#6176)
* [FEATURE] Add new form event BeforeRenderableIsValidatedEvent Resolves: TYPO3-Documentation/Changelog-To-Doc#1389 Releases: main * Update Documentation/ApiOverview/Events/Events/Form/_BeforeRenderableIsValidatedEvent/_MyEventListener.php Co-authored-by: Chris Müller <2566282+brotkrueml@users.noreply.github.com> * [TASK] Run make fix Releases: main --------- Co-authored-by: Chris Müller <2566282+brotkrueml@users.noreply.github.com>
1 parent d684af6 commit eb29f24

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.. include:: /Includes.rst.txt
2+
.. index:: Events; BeforeRenderableIsValidatedEvent
3+
4+
.. _BeforeRenderableIsValidatedEvent:
5+
6+
==================================
7+
BeforeRenderableIsValidatedEvent
8+
==================================
9+
10+
.. versionadded:: 14.0
11+
The event :php-short:`TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent`
12+
is a replacement for the removed hook
13+
:php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterSubmit']`.
14+
15+
The event :php-short:`TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent`
16+
is dispatched just before a renderable is validated. This event allows a renderable
17+
to add custom logic before it is validated.
18+
19+
20+
.. _BeforeRenderableIsValidatedEvent-example:
21+
22+
Example
23+
=======
24+
25+
.. literalinclude:: _BeforeRenderableIsValidatedEvent/_MyEventListener.php
26+
:caption: EXT:my_extension/Classes/EventListener/MyEventListener.php
27+
28+
.. _BeforeRenderableIsValidatedEvent-api:
29+
30+
API
31+
===
32+
33+
.. include:: /CodeSnippets/Events/Form/BeforeRenderableIsValidatedEvent.rst.txt
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MyVendor\MyExtension\EventListener;
6+
7+
use TYPO3\CMS\Core\Attribute\AsEventListener;
8+
use TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent;
9+
10+
final readonly class MyEventListener
11+
{
12+
#[AsEventListener(
13+
identifier: 'my-extension/before-renderable-is-validate',
14+
)]
15+
public function __invoke(BeforeRenderableIsValidatedEvent $event): void
16+
{
17+
$renderable = $event->renderable;
18+
if ($renderable->getType() !== 'AdvancedPassword') {
19+
return;
20+
}
21+
22+
$elementValue = $event->value;
23+
if ($elementValue['password'] !== $elementValue['confirmation']) {
24+
$processingRule = $renderable->getRootForm()->getProcessingRule($renderable->getIdentifier());
25+
$processingRule->getProcessingMessages()->addError(
26+
GeneralUtility::makeInstance(
27+
Error::class,
28+
GeneralUtility::makeInstance(TranslationService::class)->translate('validation.error.1556283177', null, 'EXT:form/Resources/Private/Language/locallang.xlf'),
29+
1556283177,
30+
),
31+
);
32+
}
33+
$event->value = $elementValue['password'];
34+
}
35+
}

Documentation/CodeSnippets/Config/Api/Events/EventsForm.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
'targetFileName' => 'CodeSnippets/Events/Form/BeforeRenderableIsRemovedFromFormEvent.rst.txt',
3838
'withCode' => false,
3939
],
40+
[
41+
'action' => 'createPhpClassDocs',
42+
'class' => \TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent::class,
43+
'targetFileName' => 'CodeSnippets/Events/Form/BeforeRenderableIsRemovedFromFormEvent.rst.txt',
44+
'withCode' => false,
45+
],
4046
[
4147
'action' => 'createPhpClassDocs',
4248
'class' => \TYPO3\CMS\Form\Event\BeforeFormIsDuplicatedEvent::class,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
2+
.. php:namespace:: TYPO3\CMS\Form\Event
3+
4+
.. php:class:: BeforeRenderableIsValidatedEvent
5+
6+
Listeners to this event can add custom validation logic.
7+
8+
.. php:attr:: renderable
9+
:public:
10+
11+
.. php:attr:: formRuntime
12+
:public:
13+
14+
.. php:attr:: value
15+
:public:
16+
17+
.. php:attr:: request
18+
:public:

0 commit comments

Comments
 (0)