itemsProcessors: Processing of items for select, check and radio type fields
The TCA option items provides a structured and extensible way
to process items for select, check, and radio type fields. It
supersedes items by allowing multiple processors to be applied
in a defined order using a strictly typed API.
The option is defined as an array of processors. Each processor is executed sequentially based on its numerical array key, with lower values executed first. This makes it possible for extensions or integrators to add additional processing steps without replacing existing logic.
items can still be used, but items is the recommended
approach. If both items and items are configured,
both are executed. In that case, items is executed first.
TCA item processor registration
<?php
use MyVendor\MyExtension\Processors\SpecialRelationsProcessor;
return
[
// ...
'columns' => [
'relation' => [
'label' => 'Relational field',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
'value' => 0,
'label' => '',
],
],
'foreign_table' => 'some_foreign_table',
'itemsProcessors' => [
100 => [
'class' => SpecialRelationsProcessor::class,
'parameters' => [
'foo' => 'bar',
],
],
50 => [
'class' => SpecialRelationsProcessor2::class,
],
],
],
],
],
];
In this example, Special is executed before
Special.
TCA item processor implementation
All processors must implement the
Items.
Processors have two parameters:
- A
Selectinstance containing the current items.Item Collection - An
Itemsinstance providing access to table, field, row data, and configuration.Processor Context
A processor must return a
Select. Since items
are handled as objects, newly added items can no longer be represented as
untyped arrays.
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Processors;
use TYPO3\CMS\Core\DataHandling\ItemsProcessorContext;
use TYPO3\CMS\Core\DataHandling\ItemsProcessorInterface;
use TYPO3\CMS\Core\Schema\Struct\SelectItem;
use TYPO3\CMS\Core\Schema\Struct\SelectItemCollection;
final class SpecialRelationsProcessor implements ItemsProcessorInterface
{
public function processItems(
SelectItemCollection $items,
ItemsProcessorContext $context,
): SelectItemCollection {
$items->add(
new SelectItem(
type: 'select',
label: sprintf('Extra item: %s', $context->processorParameters['foo'] ?? ''),
value: 42,
)
);
return $items;
}
}
You can add your own parameters to processors. They are exposed via the processor context.
Add parameters via TCA or page TSconfig and access them through
$context->processor.
For example, the following item processor configuration:
// ...
100 => [
'class' => SpecialRelationsProcessor::class,
'parameters' => [
'foo' => 'bar',
],
],
can access $context->processor. The value can be overridden
or extended, for example via a site setting defined in page TSconfig:
TCEFORM.example_table.content.itemsProcessors.100.foo = {$myExtension.bar}
Registering item processors in FlexForms
Registration of processors is also possible inside FlexForms:
<some_selector>
<label>Choice</label>
<config>
<type>select</type>
<renderType>selectSingle</renderType>
<itemsProcessors>
<numIndex index="100">
<class>MyVendor\MyPackage\Processors\SpecialRelationsProcessor</class>
</numIndex>
</itemsProcessors>
</config>
</some_selector>