Feature: Dispatch ModifyTcaSelectFieldItemsEvent in itemsProcFunc handlers
Description
The following items handlers provided by EXT: now
dispatch the shared PSR-14 event
\FGTCLB\:
\FGTCLB\Academic Persons\ Backend\ Form Engine\ Contract Items \FGTCLB\Academic Persons\ Backend\ Form Engine\ Profile Show Fields Items
Previously the shipped select items could only be adjusted by adding items
directly (without influence on the ordering) or by implementing a custom
items replacing the shipped one. Both ways were neither convenient
nor testable.
With the dispatched event, projects can modify the available select items of
the backend form through a single PSR-14 event listener, instead of dealing
with a dozen dedicatedly named events for the same purpose. The event carries
the complete items parameters, including
table
,
field
and
items
. For a FlexForm field,
field
is the name of the
FlexForm element, for example
settings..
Example
\TYPO3\ does not exist on TYPO3 v12,
so a listener that has to run on both supported versions is registered in
Configuration/Services.yaml:
services:
MyVendor\MyExt\EventListener\ModifyTcaSelectFieldItemsEventListener:
tags:
- name: event.listener
identifier: 'my-ext/modify-academic-persons-tca-select-items'
<?php
declare(strict_types=1);
namespace MyVendor\MyExt\EventListener;
use FGTCLB\AcademicBase\Event\ModifyTcaSelectFieldItemsEvent;
final class ModifyTcaSelectFieldItemsEventListener
{
public function __invoke(ModifyTcaSelectFieldItemsEvent $event): void
{
$tableName = $event->getParameters()['table'];
$fieldName = $event->getParameters()['field'];
if ($tableName !== 'tt_content') {
// Not the table we want to handle. Skip.
return;
}
if ($fieldName === 'settings.showFields') {
$this->modifyPersonsShowFieldsSelectItems($event);
}
if ($fieldName === 'settings.selectedContracts') {
$this->modifyPersonsContractSelectItems($event);
}
}
private function modifyPersonsShowFieldsSelectItems(
ModifyTcaSelectFieldItemsEvent $event,
): void {
// This project does not show rooms, so the option is not offered.
$parameters = $event->getParameters();
$parameters['items'] = array_values(array_filter(
$parameters['items'],
static fn(array $item): bool => ($item['value'] ?? null) !== 'contracts.room',
));
$event->setParameters($parameters);
}
private function modifyPersonsContractSelectItems(
ModifyTcaSelectFieldItemsEvent $event,
): void {
$parameters = $event->getParameters();
$parameters['items'][] = [
'label' => 'LLL:EXT:my_ext/Resources/Private/Language/locallang_be.xlf:custom_contract',
'value' => 10,
];
$event->setParameters($parameters);
}
}
Impact
Nothing changes for an installation without a listener: the handlers deliver
the items they delivered before. A listener receives the items after the
handler added its own, and what it hands back with
set is
what the backend form offers.
Affected Installations
Installations that adjust the items of the contract select or of the Show only selected Fields select of the persons plugins.