ModifyTcaSelectFieldItemsEvent
\FGTCLB\ belongs to
academic_base. The item providers of several academic extensions
dispatch it when the backend builds the items of a select field, so one
listener reorders, removes or adds items of any of them. The event and its
parameters are documented in the manual of academic_base.
This page describes the fields of this extension that dispatch it.
When it is dispatched
Two item providers of this extension dispatch the event, after they added their own items to the ones the field declares:
| Item provider | Table and field | Field in the backend |
|---|---|---|
\FGTCLB\ |
tt_, FlexForm field settings. of the
list, list-and-detail, card, selected-profiles and
selected-contracts plugins | Show only selected Fields |
\FGTCLB\ |
tt_, FlexForm field settings.
of the selected-contracts plugin | Selected Contracts |
\FGTCLB\ |
tx_, field
contract, the contract of a page contact of
academic_contacts4pages | Contract |
The event is dispatched each time the backend form renders the field, not when the record is saved.
What this extension passes in
get returns the parameters of the item provider, the ones
TYPO3 hands an
items, and
set replaces them.
What a listener of these fields finds in them:
tableandfieldname the field. For a FlexForm field,tableistt_andcontent fieldthe name of the FlexForm element, for examplesettings..show Fields itemsholds the items the field declares, followed by the ones of the provider. The shown fields offerprofile.,image contracts.,position contracts.,function Type contracts.,organisational Unit contracts.,room contracts.,office Hours contracts.,physical Addresses contracts.,email Addresses contracts.andphone Numbers contracts., each in the grouplocation profileorcontracts. The contract selects offer one item per contract, its uid as the value, sorted by the last and first name of the profile.- The contract selects are already restricted to the storage folders page TSconfig names for the field, see Restrict the backend contract selects. A contract the record references is offered all the same.
rowis the record being edited, and for a FlexForm field the values of the FlexForm.flexis the content element then.Parent Database Row
In the backend form, TYPO3 v13 hands the static items of a field to the item
provider as
\TYPO3\ objects, TYPO3
v14 as arrays, and the items a provider adds are arrays on both versions. A
Select implements
\Array, so a closure typed
array that reads
$item works on both.
Example
A site does not show rooms, so editors are not offered the room in Show only selected Fields of the persons plugins:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\EventListener;
use FGTCLB\AcademicBase\Event\ModifyTcaSelectFieldItemsEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Schema\Struct\SelectItem;
final class RemoveRoomFromShownFields
{
#[AsEventListener(identifier: 'my-extension/remove-room-from-shown-fields')]
public function __invoke(ModifyTcaSelectFieldItemsEvent $event): void
{
$parameters = $event->getParameters();
if ($parameters['table'] !== 'tt_content' || $parameters['field'] !== 'settings.showFields') {
return;
}
$parameters['items'] = array_values(array_filter(
$parameters['items'],
static fn(array|SelectItem $item): bool => ($item['value'] ?? null) !== 'contracts.room',
));
$event->setParameters($parameters);
}
}
Rules and pitfalls
- Check the table and the field. The event is shared: the item providers of academic_jobs and academic_contacts4pages dispatch it as well, and the same listener is called for all of them.
- A value that is not among the items is lost on the next save. The
fields of this page store plain values, so the backend form drops a
stored value the listener removed from the items, and saving the record
writes it away. Remove only items no record uses, or keep the ones the
record in
rowreferences. - The event decides what the backend offers. What the plugins render is decided by what the content element stored.
Introduced in
- Feature: Dispatch ModifyTcaSelectFieldItemsEvent in itemsProcFunc handlers (2.4) made the item providers of this extension dispatch the event.
- Breaking: Renamed itemsProcFunc handler classes to FormEngine namespace (2.4) moved the item providers to the
\Backend\namespace.Form Engine - Feature: Restrict the backend contract selects (2.4) restricts the contract selects before the event.