ModifyInlineElementControlsEvent

New in version 12.0

This event, together with ModifyInlineElementEnabledControlsEvent, serves as a more powerful and flexible replacement for the removed hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook']

The PSR-14 event \TYPO3\CMS\Backend\Form\Event\ModifyInlineElementControlsEvent 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.

Example

Registration of the event listener in the extension's Services.yaml:

EXT:my_extension/Configuration/Services.yaml
services:
  # Place here the default dependency injection configuration

  MyVendor\MyExtension\Backend\EventListener\MyEventListener:
    tags:
      - name: event.listener
        identifier: 'my-extension/backend/modify-enabled-controls'
        method: 'modifyEnabledControls'
      - name: event.listener
        identifier: 'my-extension/backend/modify-controls'
        method: 'modifyControls'
Copied!

Read how to configure dependency injection in extensions.

The corresponding event listener class:

EXT:my_extension/Classes/Backend/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Backend\EventListener;

use TYPO3\CMS\Backend\Form\Event\ModifyInlineElementControlsEvent;
use TYPO3\CMS\Backend\Form\Event\ModifyInlineElementEnabledControlsEvent;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;

final 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>',
            );
        }
    }
}
Copied!

API

class \TYPO3\CMS\Backend\Form\Event\ ModifyInlineElementControlsEvent

Listeners to this Event will be able to modify the controls of an inline element

getControls ( )

Returns all controls with their markup

returntype

array

setControls ( array $controls)

Overwrite the controls

param array $controls

the controls

getControl ( string $identifier)

Returns the markup for the requested control

param string $identifier

the identifier

returntype

string

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

hasControl ( string $identifier)

Returns whether a control exists for the given identifier

param string $identifier

the identifier

returntype

bool

removeControl ( string $identifier)

Removes a control from the inline element, if it exists

param string $identifier

the identifier

returntype

bool

Returns:

bool Whether the control could be removed

getElementData ( )

Returns the whole element data

returntype

array

getRecord ( )

Returns the current record of the controls are created for

returntype

array

getParentUid ( )

Returns the uid of the parent (embedding) record (uid or NEW...)

returntype

string

getForeignTable ( )

Returns the table (foreign_table) the controls are created for

returntype

string

getFieldConfiguration ( )

Returns the TCA configuration of the inline record field

returntype

array

isVirtual ( )

Returns whether the current records is only virtually shown and not physically part of the parent record

returntype

bool