Item group API methods
Adding custom select item groups
Registration of a select item group takes place in
Configuration/TCA/tx_myextension_mytable.php for new TCA tables, and in
Configuration/TCA/Overrides/a_random_core_table.php
for modifying an existing TCA definition.
For existing select fields additional item groups can be added via the
api method
Extension.
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTcaSelectItemGroup(
'tt_content',
'CType',
'sliders',
'LLL:EXT:my_extension/Resources/Private/Language/locallang_db.xlf:tt_content.group.sliders',
'after:lists',
);
ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'label' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang_db.xlf:tt_content.CType.slickslider',
'value' => 'slickslider',
'icon' => 'EXT:my_extension/Resources/Public/Icons/slickslider.png',
'group' => 'sliders',
],
);
When adding a new select field, itemGroups should be added directly in the
original TCA definition without using the API method. Use the API within
TCA/ files to extend an existing TCA select
field with grouping.
Attaching select items to item groups
Using the API method
Extension,
the group key of the item specifies the id of the item group.
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTcaSelectItemGroup(
'tt_content',
'CType',
'sliders',
'LLL:EXT:my_extension/Resources/Private/Language/locallang_db.xlf:tt_content.group.sliders',
'after:lists',
);
ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'label' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang_db.xlf:tt_content.CType.slickslider',
'value' => 'slickslider',
'icon' => 'EXT:my_extension/Resources/Public/Icons/slickslider.png',
'group' => 'sliders',
],
);
History
With the introduction of the item the TCA column type select has a
clean API to group items for dropdowns in FormEngine. This was previously
handled via placeholder -- items,
which then rendered as
<optgroup>
HTML elements in a dropdown.
In larger installations or TYPO3 instances with lots of extensions, Plugins
or Content Types (tt_), or custom
Page Types (pages.) drop down lists could grow large and
adding item groups caused tedious work for developers or integrators.
Grouping can now be configured on a per-item
basis. Custom groups can be added via an API or when defining TCA for a new
table.