Skip to content

Commit bcc7de0

Browse files
[FEATURE] Add PSR-14 Event before form deletion (#1312) (#6128)
* [FEATURE] Add PSR-14 Event before form deletion (#1312) Resolves: TYPO3-Documentation/Changelog-To-Doc#1312 Releases: main * [TASK] Incorporate review changes Resolves: TYPO3-Documentation/Changelog-To-Doc#1312 Releases: main
1 parent b491067 commit bcc7de0

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
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; BeforeFormIsDeletedEvent
3+
4+
.. _BeforeFormIsDeletedEvent:
5+
6+
========================
7+
BeforeFormIsDeletedEvent
8+
========================
9+
10+
.. versionadded:: 14.0
11+
The event :php-short:`TYPO3\CMS\Form\Event\BeforeFormIsDeletedEvent`
12+
is a more powerful replacement for the removed hook
13+
:php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['beforeFormDelete']`.
14+
15+
The event :php-short:`TYPO3\CMS\Form\Event\BeforeFormIsDeletedEvent`
16+
can prevent the deletion of a form and add custom logic based on the delete
17+
action. The event is dispatched just before a form is deleted in the backend.
18+
19+
Setting :php:`$preventDeletion` to
20+
:php:`true`, stops the event and no further listener is called.
21+
22+
.. seealso::
23+
* The backend form editor is described in detail in the `TYPO3 Form manual
24+
- Form editor <https://docs.typo3.org/permalink/typo3/cms-form:apireference-formeditor>`_.
25+
26+
.. _BeforeFormIsDeletedEvent-example:
27+
28+
Example
29+
=======
30+
31+
.. literalinclude:: _BeforeFormIsDeletedEvent/_MyEventListener.php
32+
:language: php
33+
:caption: EXT:my_extension/Classes/EventListener/MyEventListener.php
34+
35+
.. _BeforeFormIsDeletedEvent-api:
36+
37+
API
38+
===
39+
40+
.. include:: /CodeSnippets/Events/Form/BeforeFormIsDeletedEvent.rst.txt
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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\BeforeFormIsDeletedEvent;
9+
10+
#[AsEventListener(
11+
identifier: 'my-extension/before-form-is-deleted',
12+
)]
13+
final readonly class MyEventListener
14+
{
15+
public function __invoke(BeforeFormIsDeletedEvent $event): void
16+
{
17+
if ($event->formPersistenceIdentifier === 'some-identifier') {
18+
$event->preventDeletion = true;
19+
}
20+
}
21+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
'targetFileName' => 'CodeSnippets/Events/Form/BeforeFormIsCreatedEvent.rst.txt',
2020
'withCode' => false,
2121
],
22+
[
23+
'action' => 'createPhpClassDocs',
24+
'class' => \TYPO3\CMS\Form\Event\BeforeFormIsDeletedEvent::class,
25+
'targetFileName' => 'CodeSnippets/Events/Form/BeforeFormIsDeletedEvent.rst.txt',
26+
'withCode' => false,
27+
],
2228
[
2329
'action' => 'createPhpClassDocs',
2430
'class' => \TYPO3\CMS\Form\Event\BeforeRenderableIsAddedToFormEvent::class,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
2+
.. php:namespace:: TYPO3\CMS\Form\Event
3+
4+
.. php:class:: BeforeFormIsDeletedEvent
5+
6+
Listeners to this event will be able to prevent deletion of a form and/or
7+
add custom logic.
8+
9+
.. php:attr:: formPersistenceIdentifier
10+
:readonly:
11+
:public:
12+
13+
.. php:attr:: preventDeletion
14+
:public:
15+
:returns: `bool`

0 commit comments

Comments
 (0)