Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v10 here: TYPO3 ELTS.
Examples
Simple category field
In the following example a category tree is displayed and multiple categories can be selected.
$GLOBALS['TCA'][$myTable]['columns']['categories'] = [
'config' => [
'type' => 'category'
]
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
$myTable,
'categories'
);
The relationship gets stored in the intermediate table
sys_
. Category counts are only stored on the
local side.
Note
This is the use case, which was previously accomplished using
Extension
up to v11.
One to one relation category field
In the following example a category tree is displayed, but only one category can be selected.
$GLOBALS['TCA'][$myTable]['columns']['mainCategory'] = [
'config' => [
'type' => 'category',
'relationship' => 'oneToOne'
]
];
Category field used in FlexForm
It is possible to use the type category
in FlexForm data structures.
Due to some limitations in FlexForm, the many
relationship is not
supported. Therefore, the default relationship - used if none is defined -
is one
.
An example of the "oneToMany" use case is EXT:news, which allows to only display news of specific categories in the list view:
<T3DataStructure>
<ROOT>
<TCEforms>
<sheetTitle>aTitle</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<categories>
<TCEforms>
<config>
<type>category</type>
</config>
</TCEforms>
</categories>
</el>
</ROOT>
</T3DataStructure>