itemsProcFunc
-
- Type
- string (class->method reference)
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['itemsProcFunc']
- Scope
- Display / Proc.
- Types
- check, select, radio
PHP method which is called to fill or manipulate the items array. It is recommended to use the actual FQCN with
classand then concatenate the method:\MyVendor\ My Extension\ User Function\ Form Engine\ Your Class:: class . '->your Method' This becomes handy when using an IDE and doing operations like renaming classes.
The provided method will have an array of parameters passed to it. The items array is passed by reference in the key
items. By modifying the array of items, you alter the list of items. A method may throw an exception which will be displayed as a proper error message to the user.
Passed parameters
items(passed by reference)config(TCA config of the field)TSconfig(The matching itemsProcFunc TSconfig)table(current table)row(current database record)field(current field name)effective(correct page ID)Pid site(current site)
The following parameter only exists if the field has a flex parent.
flexParent Database Row
The following parameters are filled if the current record has an inline parent.
inlineParent Uid inlineParent Table Name inlineParent Field Name inlineParent Config inlineTop Most Parent Uid inlineTop Most Parent Table Name inlineTop Most Parent Field Name
Example
A talk belongs to one track of its conference. The conference lists its tracks in a text field, one per line:
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
// The tracks of the program, which the talks offer as items
ExtensionManagementUtility::addTCAcolumns('tx_myextension_conference', [
'tracks' => [
'label' => 'my_extension.db:conference.tracks',
'description' => 'my_extension.db:conference.tracks.description',
'config' => [
'type' => 'text',
'rows' => 4,
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_conference',
'tracks',
'',
'after:partners',
);
The field track of the talk adds these tracks as items:
The track of a talk
<?php
use MyVendor\MyExtension\Backend\TrackItems;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTCAcolumns('tx_myextension_talk', [
'track' => [
'label' => 'my_extension.db:talk.track',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['label' => '', 'value' => ''],
],
// Adds the tracks of the conference of the talk
'itemsProcFunc' => TrackItems::class . '->addTracks',
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_talk',
'track',
'',
'after:room',
);
The referenced items method should populate the items by filling
$params:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Backend;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Offers the tracks of the conference of a talk, one per line in the field
* "tracks" of the conference
*/
final class TrackItems
{
public function addTracks(array &$params): void
{
// A new talk is not stored yet, its conference is the inline parent
$conference = (int)($params['row']['conference'] ?? 0)
?: (int)($params['inlineParentUid'] ?? 0);
$record = BackendUtility::getRecord('tx_myextension_conference', $conference, 'tracks');
$tracks = GeneralUtility::trimExplode("\n", (string)($record['tracks'] ?? ''), true);
foreach ($tracks as $track) {
$params['items'][] = ['label' => $track, 'value' => $track];
}
}
}
The method uses the passed parameter row to find the conference of the
talk. A new talk is not stored yet, so its conference is the inline parent
in inline.