itemsProcFunc

itemsProcFunc
Path

$GLOBALS['TCA'][$table]['columns'][$field]['config']

type

string (class->method reference)

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:

\VENDOR\Extension\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

New in version 12.4.10

The parameters effectivePid and site have been added.

  • 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

New in version 11.2

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

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

Example

The configuration for a custom field select_single_2 could look like this:

'select_single_2' => [
    'exclude' => 1,
    'label' => 'select_single_2 itemsProcFunc',
    'config' => [
        'type' => 'select',
        'renderType' => 'selectSingle',
        'items' => [
            ['label' => 'foo', 'value' => 1],
            ['label' => 'bar', 'value' => 'bar'],
        ],
        'itemsProcFunc' => TYPO3\CMS\Styleguide\UserFunctions\FormEngine\TypeSelect2ItemsProcFunc::class . '->itemsProcFunc',
    ],
]
Copied!

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

/**
 * A user function used in select_2
 */
class TypeSelect2ItemsProcFunc
{
    /**
     * Add two items to existing ones
     *
     * @param array $params
     */
    public function itemsProcFunc(&$params): void
    {
        $params['items'][] = ['label' => 'item 1 from itemProcFunc()', 'value' => 'val1'];
        $params['items'][] = ['label' => 'item 2 from itemProcFunc()', 'value' => 'val2'];
    }
}
Copied!

This results in the rendered select dropdown having four items. This is a really simple example. In the real world you would use the other passed parameters to dynamically generate the items.