ModifyTcaSelectFieldItemsEvent
\FGTCLB\ belongs to
academic_base. The academic extensions dispatch it from the item
providers of their backend select fields, so a listener changes the items an
editor is offered without replacing the item provider. The event is described
on its page in the manual of academic_base.
This page describes the selects of academic_contacts4pages that
dispatch it.
When it is dispatched
\FGTCLB\
dispatches it each time the backend form of a contact builds the items of one of
its three address selects:
| Field | Label | Method of the item provider |
|---|---|---|
email_ | E-mail address |
email |
phone_ | Phone number |
phone |
physical_ | Physical address |
physical |
The table is tx_, in the form of a
contact on its own and inline in the tab Contacts of a page or
Linked pages of a contract. The event is dispatched after the item
provider replaced the record items TYPO3 added with its own list, so a listener
receives the final items.
The Contract select of a contact is filled by the item provider of
academic_persons, which dispatches the same event for the field
contract of this table. Its page in the manual of academic_persons
describes the selects it fills.
What this extension passes in
| Method | Returns or does |
|---|---|
get | The parameters of the item provider:
items
,
table
,
field
,
row
,
config
,
TSconfig
,
effective,
site
and the inline parent keys. The
uids of the inline parents are the empty string '' unless the
contact is edited inline, and a NEW... string for a parent
that is not saved yet. |
set | Replaces the parameters. What counts is
items
, the list the
select offers. |
The items of an address select:
- Display all with the value
0, the default of the field, and Do not display with the value-1. - One item per address of the contract the contact names, with the uid of the address as the value and a label built from its type and its text. Hidden addresses are offered too, marked as hidden. Only addresses of the default language and of the workspace of the editor are offered.
In the backend form, TYPO3 v13 and v14 hand the static items of a field to the
item provider as
\TYPO3\ objects,
and the items a provider adds are arrays. A
Select implements
\Array, so a closure typed
array that reads
$item works for both.
Example
A site wants every contact on its pages to show a phone number, and takes Do not display out of the phone number select:
<?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 AlwaysShowAPhoneNumberOfPageContacts
{
#[AsEventListener(identifier: 'my-extension/always-show-a-phone-number-of-page-contacts')]
public function __invoke(ModifyTcaSelectFieldItemsEvent $event): void
{
$parameters = $event->getParameters();
if ($parameters['table'] !== 'tx_academiccontacts4pages_domain_model_contact'
|| $parameters['field'] !== 'phone_number'
) {
return;
}
$parameters['items'] = array_values(array_filter(
$parameters['items'],
// -1 is "Do not display".
static fn(array|SelectItem $item): bool => (int)($item['value'] ?? 0) !== -1,
));
$event->setParameters($parameters);
}
}
Rules and pitfalls
Check the table and the field. One listener receives the event of every select of every academic extension that dispatches it.
A removed item does not change stored values. A contact that stores the value of an item a listener removed keeps it. The form shows it as an invalid value, and the frontend renders it as before, until an editor picks another item. Do not remove Display all, the value a new contact gets.
The items are what the editor is offered, not what the frontend shows. The frontend renders the addresses the contact selects, and hidden ones only while Show hidden records is on. An item a listener adds whose value is no address of the contract shows no address of that kind in the frontend.
Introduced in
- Feature: Dedicated selection of address records added the three selects in version 2.4, and with them the dispatch.
- Important: The address selects of a page contact are relations made the selects relations to the address tables in version 2.4, and states that a listener receives the final item list.