itemsProcFunc 

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 class and then concatenate the method:

\MyVendor\MyExtension\UserFunction\FormEngine\YourClass::class . '->yourMethod'

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)
  • effectivePid (correct page ID)
  • site (current site)

The following parameter only exists if the field has a flex parent.

  • flexParentDatabaseRow

The following parameters are filled if the current record has an inline parent.

  • inlineParentUid
  • inlineParentTableName
  • inlineParentFieldName
  • inlineParentConfig
  • inlineTopMostParentUid
  • inlineTopMostParentTableName
  • inlineTopMostParentFieldName

Example 

A talk belongs to one track of its conference. The conference lists its tracks in a text field, one per line:

EXT:my_extension/Configuration/TCA/Overrides/129-tx_myextension_conference-tracks.php
<?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',
);
Copied!

The field track of the talk adds these tracks as items:

The track of a talk

The track of a talk

EXT:my_extension/Configuration/TCA/Overrides/290-tx_myextension_talk-track.php
<?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',
);
Copied!

The referenced itemsProcFunc method should populate the items by filling $params['items'] :

EXT:my_extension/Classes/Backend/TrackItems.php
<?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];
    }
  }
}
Copied!

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 inlineParentUid.