Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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,40 @@
.. include:: /Includes.rst.txt
.. index:: Events; BeforeFormIsDeletedEvent

.. _BeforeFormIsDeletedEvent:

========================
BeforeFormIsDeletedEvent
========================

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

The event :php-short:`TYPO3\CMS\Form\Event\BeforeFormIsDeletedEvent`
can prevent the deletion of a form and add custom logic based on the delete
action. The event is dispatched just before a form is deleted in the backend.

Setting :php:`$preventDeletion` to
:php:`true`, stops the event and no further listener is called.

.. seealso::
* The backend form editor is described in detail in the `TYPO3 Form manual
- Form editor <https://docs.typo3.org/permalink/typo3/cms-form:apireference-formeditor>`_.

.. _BeforeFormIsDeletedEvent-example:

Example
=======

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

.. _BeforeFormIsDeletedEvent-api:

API
===

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

declare(strict_types=1);

namespace MyVendor\MyExtension\EventListener;

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

#[AsEventListener(
identifier: 'my-extension/before-form-is-deleted',
)]
final readonly class MyEventListener
{
public function __invoke(BeforeFormIsDeletedEvent $event): void
{
if ($event->formPersistenceIdentifier === 'some-identifier') {
$event->preventDeletion = true;
}
}
}
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 @@ -19,6 +19,12 @@
'targetFileName' => 'CodeSnippets/Events/Form/BeforeFormIsCreatedEvent.rst.txt',
'withCode' => false,
],
[
'action' => 'createPhpClassDocs',
'class' => \TYPO3\CMS\Form\Event\BeforeFormIsDeletedEvent::class,
'targetFileName' => 'CodeSnippets/Events/Form/BeforeFormIsDeletedEvent.rst.txt',
'withCode' => false,
],
[
'action' => 'createPhpClassDocs',
'class' => \TYPO3\CMS\Form\Event\BeforeRenderableIsAddedToFormEvent::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
.. php:namespace:: TYPO3\CMS\Form\Event

.. php:class:: BeforeFormIsDeletedEvent

Listeners to this event will be able to prevent deletion of a form and/or
add custom logic.

.. php:attr:: formPersistenceIdentifier
:readonly:
:public:

.. php:attr:: preventDeletion
:public:
:returns: `bool`