Feature: #94622 - New TCA type "category"¶
See forge#94622
Description¶
A new TCA field type called category
has been added to TYPO3 Core.
Its main purpose is to simplify the TCA configuration when adding a category
tree to a record. It therefore supersedes the \TYPO3\
as well
as the \TYPO3\
, which required
creating a "TCA overrides" file.
Both, the Category
as well as
Extension
are going to be
deprecated in the future.
While using the new type, TYPO3 takes care of generating the necessary TCA configuration and also adds the database column automatically. Developers only have to configure the TCA column and add it to the desired record types.
$GLOBALS['TCA'][$myTable]['columns']['categories'] = [
'config' => [
'type' => 'category'
]
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes($myTable, 'categories');
The above example does not contain the new option relationship
since the the default is many
. All possible values are:
one
: Stores the uid of the selected category. When using this relationship,To One maxitems=1
will automatically be added to the column configurationone
: Stores the uids of selected categories in a comma-separated listTo Many many
(default): Uses the intermediate tableTo Many sys_
and only stores the categories count on the local side. This is the use case, which was previously accomplished usingcategory_ record_ mm Extension
.Management Utility->make Categorizable ()
This means, the new type can not only be used with relationship=many
as
a replacement for make
but can be used for other use
cases too. In case a category tree is required, only allowing one category
to be selected, the necessary configuration reduces to
$GLOBALS['TCA'][$myTable]['columns']['mainCategory'] = [
'config' => [
'type' => 'category',
'relationship' => 'oneToOne'
]
];
All other relevant options, e.g. maxitems=1
, are being set automatically.
Besides type
and relationship
, following type specific options
are available:
default
exclusive
: As known fromKeys render
Type=select Tree tree
: As known fromConfig render
Type=select Tree
It's possible to use TSconfig options, such as
remove
. However, adding static items with TSconfig is not
implemented for this type. For such special cases, please continue using TCA
type select
.
The Override matrix - specifying the options which can be overridden in TSconfig - is extended for the new type. Following options can be overridden:
size
maxitems
minitems
read
Only tree
Config
Note
It's still possible to configure a category tree with type=select
and render
. This configuration will still work, but
could in most cases be simplified, using the new category
TCA type.
Flexform usage¶
It's also possible to use the new type in flexform data structures. However, due to some limitations in flexform, the "manyToMany" relationship is not supported. Therefore, the default relationship - used if none is defined - is "oneToMany". This is anyways the most common use case for flexforms, as it's not important to look from the other side "which flexform elements reference this category". 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>
Impact¶
It's now possible to simplify the TCA configuration for category fields,
using the new TCA type category
.