How to limit the TYPO3 category tree to a subset of categories for extension records
In many TYPO3 projects I’ve been working in, the TYPO3 category system is used to structure content by one or multiple categories. A typical category tree I often see is build up as shown in the example below:
This is a very plain way to create a category tree and the structure in the example is limited to 3 independent main categories (Events, Products, Staff).
Quite often, the shown example category tree is used systemwide in TYPO3 and all main categories are shown for all record types. This can be confusing for editors, since when you for example want to assign categories for e.g. event records, why should one see and be able to select the categories “Products” and “Staff” including all subcategories?
Fortunately TYPO3 can be configured to limit the category tree for tables to a given root category. As an example, I limit the shown categories for event records to only “Event” categories. I assume that the category “Events” has the sys_category UID 1.
PageTS example
In PageTS such configuration options can be set for any record as long as the following configuration path is met:
TCEFORM.[tableName].[fieldName].[propertyName]
The fieldName is usually “categories” or “category”, but this can also be different depending on how categories are implemented in 3rd party extensions.
The PageTS setting can also be set in TCA as shown below.
TCA example
As a result, the category tree for event records is now limited to the category “Events” and all subcategories.
I think this is way more clear for an editor than it was before. In general, this can be configured for every table in the TYPO3 TCA (e.g. pages, files, extensions, …)
The configuration only allows to define one UID as root for the category tree. If more flexibility is needed to limiting
the category tree, then TCEFORM.[tableName].[fieldName].[config][foreign_table_where]
may be the place to add
own custom conditions.
Note, that the old configuration option rootUid
is deprecated since TYPO3 11.5 and that with TYPO3 11.5+
only startingPoints
should be used. As a bonus, it is possible to select multiple category UIDs as startingpoint.