Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Feature: #97231 - PSR-14 Events for modifying inline elemen… #1797

Merged
merged 1 commit into from
Apr 6, 2022
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,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