Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.. include:: /Includes.rst.txt
.. index:: Events; BeforeRenderableIsValidatedEvent

.. _BeforeRenderableIsValidatedEvent:

==================================
BeforeRenderableIsValidatedEvent
==================================

.. versionadded:: 14.0
The event :php-short:`TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent`
is a replacement for the removed hook
:php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterSubmit']`.

The event :php-short:`TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent`
is dispatched just before a renderable is validated. This event allows a renderable
to add custom logic before it is validated.


.. _BeforeRenderableIsValidatedEvent-example:

Example
=======

.. literalinclude:: _BeforeRenderableIsValidatedEvent/_MyEventListener.php
:caption: EXT:my_extension/Classes/EventListener/MyEventListener.php

.. _BeforeRenderableIsValidatedEvent-api:

API
===

.. include:: /CodeSnippets/Events/Form/BeforeRenderableIsValidatedEvent.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent;

final readonly class MyEventListener
{
#[AsEventListener(
identifier: 'my-extension/before-renderable-is-validate',
)]
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'];
}
}
6 changes: 6 additions & 0 deletions Documentation/CodeSnippets/Config/Api/Events/EventsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
'targetFileName' => 'CodeSnippets/Events/Form/BeforeRenderableIsRemovedFromFormEvent.rst.txt',
'withCode' => false,
],
[
'action' => 'createPhpClassDocs',
'class' => \TYPO3\CMS\Form\Event\BeforeRenderableIsValidatedEvent::class,
'targetFileName' => 'CodeSnippets/Events/Form/BeforeRenderableIsRemovedFromFormEvent.rst.txt',
'withCode' => false,
],
[
'action' => 'createPhpClassDocs',
'class' => \TYPO3\CMS\Form\Event\BeforeFormIsDuplicatedEvent::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
.. php:namespace:: TYPO3\CMS\Form\Event

.. php:class:: BeforeRenderableIsValidatedEvent

Listeners to this event can add custom validation logic.

.. php:attr:: renderable
:public:

.. php:attr:: formRuntime
:public:

.. php:attr:: value
:public:

.. php:attr:: request
:public:
Loading