-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Feature: #97231 - PSR-14 Events for modifying inline elemen…
…t controls (#1797) https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Feature-97231-PSR-14EventsForModifyingInlineElementControls.html refs #1624 Co-authored-by: lina.wolf <[email protected]>
- Loading branch information
Showing
4 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...mentation/ApiOverview/Hooks/Events/Backend/ModifyInlineElementControlsEvent.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
.. include:: /Includes.rst.txt | ||
.. index:: Events; ModifyInlineElementControlsEvent | ||
.. _ModifyInlineElementControlsEvent: | ||
|
||
==================================== | ||
ModifyInlineElementControlsEvent | ||
==================================== | ||
|
||
.. versionadded:: 12.0 | ||
This event, together with :ref:`ModifyInlineElementEnabledControlsEvent` | ||
serves as a more powerful and flexible replacement | ||
for the removed hook :php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook']` | ||
|
||
This event | ||
is called after the markup for all enabled controls has been generated. It | ||
can be used to either change the markup of a control, to add a new control | ||
or to completely remove a control. | ||
|
||
API | ||
=== | ||
|
||
.. include:: /CodeSnippets/Events/Backend/ModifyInlineElementControlsEvent.rst.txt | ||
|
||
.. _ModifyInlineElementControlsEvent_example: | ||
|
||
Example | ||
======= | ||
|
||
Registration of the Event in your extensions' :file:`Services.yaml`: | ||
|
||
.. code-block:: yaml | ||
:caption: my_extension/Configuration/Services.yaml | ||
MyVendor\MyPackage\Backend\MyEventListener: | ||
tags: | ||
- name: event.listener | ||
identifier: 'my-package/backend/modify-enabled-controls' | ||
method: 'modifyEnabledControls' | ||
- name: event.listener | ||
identifier: 'my-package/backend/modify-controls' | ||
method: 'modifyControls' | ||
The corresponding event listener class: | ||
|
||
.. code-block:: php | ||
use TYPO3\CMS\Backend\Form\Event\ModifyInlineElementEnabledControlsEvent; | ||
use TYPO3\CMS\Backend\Form\Event\ModifyInlineElementControlsEvent; | ||
use TYPO3\CMS\Core\Imaging\Icon; | ||
use TYPO3\CMS\Core\Imaging\IconFactory; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
class MyEventListener { | ||
public function modifyEnabledControls(ModifyInlineElementEnabledControlsEvent $event): void | ||
{ | ||
// Enable a control depending on the foreign table | ||
if ($event->getForeignTable() === 'sys_file_reference' && $event->isControlEnabled('sort')) { | ||
$event->enableControl('sort'); | ||
} | ||
} | ||
public function modifyControls(ModifyInlineElementControlsEvent $event): void | ||
{ | ||
// Add a custom control depending on the parent table | ||
if ($event->getElementData()['inlineParentTableName'] === 'tt_content') { | ||
$iconFactory = GeneralUtility::makeInstance(IconFactory::class); | ||
$event->setControl( | ||
'tx_my_control', | ||
'<a href="/some/url" class="btn btn-default t3js-modal-trigger">' . $iconFactory->getIcon('my-icon-identifier', Icon::SIZE_SMALL)->render() . '</a>' | ||
); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...on/ApiOverview/Hooks/Events/Backend/ModifyInlineElementEnabledControlsEvent.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.. include:: /Includes.rst.txt | ||
.. index:: Events; ModifyInlineElementEnabledControlsEvent | ||
.. _ModifyInlineElementEnabledControlsEvent: | ||
|
||
======================================= | ||
ModifyInlineElementEnabledControlsEvent | ||
======================================= | ||
|
||
.. versionadded:: 12.0 | ||
This event, together with :ref:`ModifyInlineElementControlsEvent` | ||
serves as a more powerful and flexible replacement | ||
for the removed hook :php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook']` | ||
|
||
This event | ||
is called before any control markup is generated. It can be used to | ||
enable or disable each control. With this event it is therefore possible | ||
to enable a control, which is disabled in TCA, only for some use case. | ||
|
||
For an example see | ||
:ref:`ModifyInlineElementControlsEvent Example <ModifyInlineElementControlsEvent_example>`. | ||
|
||
API | ||
=== | ||
|
||
.. include:: /CodeSnippets/Events/Backend/ModifyInlineElementEnabledControlsEvent.rst.txt |
86 changes: 86 additions & 0 deletions
86
Documentation/CodeSnippets/Events/Backend/ModifyInlineElementControlsEvent.rst.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
.. Generated by https://github.com/linawolf/t3docs_restructured_api_tools | ||
.. php:namespace:: TYPO3\CMS\Backend\Form\Event | ||
.. php:class:: ModifyInlineElementControlsEvent | ||
Listeners to this Event will be able to modify the controls of an inline element | ||
|
||
|
||
.. php:method:: getControls() | ||
Returns all controls with their markup | ||
|
||
:returntype: array | ||
|
||
.. php:method:: setControls(array controls) | ||
Overwrite the controls | ||
|
||
:param array $controls: the controls | ||
|
||
.. php:method:: getControl(string identifier) | ||
Returns the markup for the requested control | ||
|
||
:param string $identifier: the identifier | ||
:returntype: string | ||
|
||
.. php:method:: setControl(string identifier, string markup) | ||
Set a control with the given identifier and markup | ||
IMPORTANT: Overwrites an existing control with the same identifier | ||
|
||
:param string $identifier: the identifier | ||
:param string $markup: the markup | ||
|
||
.. php:method:: hasControl(string identifier) | ||
Returns whether a control exists for the given identifier | ||
|
||
:param string $identifier: the identifier | ||
:returntype: bool | ||
|
||
.. php:method:: removeControl(string identifier) | ||
Removes a control from the inline element, if it exists | ||
|
||
:param string $identifier: the identifier | ||
:returntype: bool | ||
:returns: Whether the control could be removed | ||
|
||
.. php:method:: getElementData() | ||
Returns the whole element data | ||
|
||
:returntype: array | ||
|
||
.. php:method:: getRecord() | ||
Returns the current record of the controls are created for | ||
|
||
:returntype: array | ||
|
||
.. php:method:: getParentUid() | ||
Returns the uid of the parent (embedding) record (uid or NEW...) | ||
|
||
:returntype: string | ||
|
||
.. php:method:: getForeignTable() | ||
Returns the table (foreign_table) the controls are created for | ||
|
||
:returntype: string | ||
|
||
.. php:method:: getFieldConfiguration() | ||
Returns the TCA configuration of the inline record field | ||
|
||
:returntype: array | ||
|
||
.. php:method:: isVirtual() | ||
Returns whether the current records is only virtually shown and not physically part of the parent record | ||
|
||
:returntype: bool | ||
|
88 changes: 88 additions & 0 deletions
88
...ion/CodeSnippets/Events/Backend/ModifyInlineElementEnabledControlsEvent.rst.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
.. Generated by https://github.com/linawolf/t3docs_restructured_api_tools | ||
.. php:namespace:: TYPO3\CMS\Backend\Form\Event | ||
.. php:class:: ModifyInlineElementEnabledControlsEvent | ||
Listeners to this Event will be able to modify the state (enabled or disabled) for controls of an inline element | ||
|
||
|
||
.. php:method:: enableControl(string identifier) | ||
Enable a control, if it exists | ||
|
||
:param string $identifier: the identifier | ||
:returntype: bool | ||
:returns: Whether the control could be enabled | ||
|
||
.. php:method:: disableControl(string identifier) | ||
Disable a control, if it exists | ||
|
||
:param string $identifier: the identifier | ||
:returntype: bool | ||
:returns: Whether the control could be disabled | ||
|
||
.. php:method:: hasControl(string identifier) | ||
Returns whether a control exists for the given identifier | ||
|
||
:param string $identifier: the identifier | ||
:returntype: bool | ||
|
||
.. php:method:: isControlEnabled(string identifier) | ||
Returns whether the control is enabled. | ||
|
||
Note: Will also return FALSE in case no control exists for the requested identifier | ||
|
||
:param string $identifier: the identifier | ||
:returntype: bool | ||
|
||
.. php:method:: getControlsState() | ||
Returns all controls with their state (enabled or disabled) | ||
|
||
:returntype: array | ||
|
||
.. php:method:: getEnabledControls() | ||
Returns all enabled controls | ||
|
||
:returntype: array | ||
|
||
.. php:method:: getElementData() | ||
Returns the whole element data | ||
|
||
:returntype: array | ||
|
||
.. php:method:: getRecord() | ||
Returns the current record of the controls are created for | ||
|
||
:returntype: array | ||
|
||
.. php:method:: getParentUid() | ||
Returns the uid of the parent (embedding) record (uid or NEW...) | ||
|
||
:returntype: string | ||
|
||
.. php:method:: getForeignTable() | ||
Returns the table (foreign_table) the controls are created for | ||
|
||
:returntype: string | ||
|
||
.. php:method:: getFieldConfiguration() | ||
Returns the TCA configuration of the inline record field | ||
|
||
:returntype: array | ||
|
||
.. php:method:: isVirtual() | ||
Returns whether the current records is only virtually shown and not physically part of the parent record | ||
|
||
:returntype: bool | ||
|