Skip to content

Commit

Permalink
[FEATURE] Feature: #97231 - PSR-14 Events for modifying inline elemen…
Browse files Browse the repository at this point in the history
  • Loading branch information
linawolf and linawolf authored Apr 6, 2022
1 parent d09596f commit 4140998
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 0 deletions.
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>'
);
}
}
}
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
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

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

0 comments on commit 4140998

Please sign in to comment.