WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 59c26a0

Browse files
authored
[!!!][FEATURE] Add PSR-14 Events to manipulate form before created or… (#6006)
* [!!!][FEATURE] Add PSR-14 Events to manipulate form before created or saved Resolves: https://review.typo3.org/c/Packages/TYPO3.CMS/+/90561 Resolves: TYPO3-Documentation/Changelog-To-Doc#1309 Releases: main * [!!!][FEATURE] Add PSR-14 Events to manipulate form before created or saved Resolves: https://review.typo3.org/c/Packages/TYPO3.CMS/+/90561 Resolves: TYPO3-Documentation/Changelog-To-Doc#1309 Releases: main * Correction from code review
1 parent 213ea4e commit 59c26a0

File tree

7 files changed

+157
-0
lines changed

7 files changed

+157
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. include:: /Includes.rst.txt
2+
.. index:: Events; BeforeFormIsCreatedEvent
3+
4+
.. _BeforeFormIsCreatedEvent:
5+
6+
========================
7+
BeforeFormIsCreatedEvent
8+
========================
9+
10+
.. versionadded:: 14.0
11+
The event :php-short:`TYPO3\CMS\Form\Event\BeforeFormIsCreatedEvent`
12+
serves as a direct replacement for the removed hook
13+
:php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['beforeFormCreate']`.
14+
15+
The event :php-short:`TYPO3\CMS\Form\Event\BeforeFormIsCreatedEvent` allows a
16+
to modify a form before it gets created. The event is dispatched just right
17+
before a new form is created in the backend.
18+
19+
.. seealso::
20+
* `BeforeFormIsSavedEvent <https://docs.typo3.org/permalink/t3coreapi:beforeformissavedevent>`_
21+
is called right before a form is saved in the backend form editor.
22+
* The backend form editor is described in detail in the `TYPO3 Form manual
23+
- Form editor <https://docs.typo3.org/permalink/typo3/cms-form:apireference-formeditor>`_.
24+
25+
.. _BeforeFormIsCreatedEvent-example:
26+
27+
Example
28+
=======
29+
30+
.. literalinclude:: _BeforeFormIsCreatedEvent/_MyEventListener.php
31+
:language: php
32+
:caption: EXT:my_extension/Classes/EventListener/MyEventListener.php
33+
34+
.. include:: /_includes/EventsAttributeAddedNew.rst.txt
35+
36+
.. _BeforeFormIsCreatedEvent-api:
37+
38+
API
39+
===
40+
41+
.. include:: /CodeSnippets/Events/Form/BeforeFormIsCreatedEvent.rst.txt
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. include:: /Includes.rst.txt
2+
.. index:: Events; BeforeFormIsSavedEvent
3+
4+
.. _BeforeFormIsSavedEvent:
5+
6+
======================
7+
BeforeFormIsSavedEvent
8+
======================
9+
10+
.. versionadded:: 14.0
11+
The event :php-short:`TYPO3\CMS\Form\Event\BeforeFormIsSavedEvent`
12+
serves as a direct replacement for the removed hook
13+
:php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['beforeFormSave']`.
14+
15+
The event :php-short:`TYPO3\CMS\Form\Event\BeforeFormIsSavedEvent` allows a
16+
to modify a form definition as well as the form persistence identifier before
17+
it gets saved. It is dispatched just right before a form is saved in the backend.
18+
19+
.. seealso::
20+
* `BeforeFormIsCreatedEvent <https://docs.typo3.org/permalink/t3coreapi:beforeformiscreatedevent>`_
21+
is called right before a form is created in the backend form editor.
22+
* The backend form editor is described in detail in the `TYPO3 Form manual
23+
- Form editor <https://docs.typo3.org/permalink/typo3/cms-form:apireference-formeditor>`_.
24+
25+
.. _BeforeFormIsSavedEvent-example:
26+
27+
Example
28+
=======
29+
30+
.. literalinclude:: _BeforeFormIsSavedEvent/_MyEventListener.php
31+
:caption: EXT:my_extension/Classes/EventListener/MyEventListener.php
32+
33+
.. include:: /_includes/EventsAttributeAddedNew.rst.txt
34+
35+
.. _BeforeFormIsSavedEvent-api:
36+
37+
API
38+
===
39+
40+
.. include:: /CodeSnippets/Events/Form/BeforeFormIsSavedEvent.rst.txt
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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\BeforeFormIsCreatedEvent;
9+
10+
#[AsEventListener(
11+
identifier: 'my-extension/before-form-is-created',
12+
)]
13+
final readonly class MyEventListener
14+
{
15+
public function __invoke(BeforeFormIsCreatedEvent $event): void
16+
{
17+
$event->form['label'] = 'foo';
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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\BeforeFormIsSavedEvent;
9+
10+
#[AsEventListener(
11+
identifier: 'my-extension/before-form-is-saved',
12+
)]
13+
final readonly class MyEventListener
14+
{
15+
public function __invoke(BeforeFormIsSavedEvent $event): void
16+
{
17+
$event->form['label'] = 'foo';
18+
}
19+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,16 @@
77
'targetFileName' => 'CodeSnippets/Events/Form/AfterFormDefinitionLoadedEvent.rst.txt',
88
'withCode' => false,
99
],
10+
[
11+
'action' => 'createPhpClassDocs',
12+
'class' => \TYPO3\CMS\Form\Event\BeforeFormIsSavedEvent::class,
13+
'targetFileName' => 'CodeSnippets/Events/Form/BeforeFormIsSavedEvent.rst.txt',
14+
'withCode' => false,
15+
],
16+
[
17+
'action' => 'createPhpClassDocs',
18+
'class' => \TYPO3\CMS\Form\Event\BeforeFormIsCreatedEvent::class,
19+
'targetFileName' => 'CodeSnippets/Events/Form/BeforeFormIsCreatedEvent.rst.txt',
20+
'withCode' => false,
21+
],
1022
];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
2+
.. php:namespace:: TYPO3\CMS\Form\Event
3+
4+
.. php:class:: BeforeFormIsCreatedEvent
5+
6+
Listeners to this Event will be able to modify the form definition
7+
and persistence identifier before a new form is created.
8+
9+
.. php:attr:: formPersistenceIdentifier
10+
:public:
11+
12+
.. php:attr:: form
13+
:public:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
2+
.. php:namespace:: TYPO3\CMS\Form\Event
3+
4+
.. php:class:: BeforeFormIsSavedEvent
5+
6+
Listeners to this Event will be able to modify the form definition
7+
and persistence identifier before a form is saved.
8+
9+
.. php:attr:: formPersistenceIdentifier
10+
:public:
11+
12+
.. php:attr:: form
13+
:public:

0 commit comments

Comments
 (0)