Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: #94622 - New TCA type "category" #4418

Open
simonschaufi opened this issue Oct 30, 2024 · 0 comments
Open

Feature: #94622 - New TCA type "category" #4418

simonschaufi opened this issue Oct 30, 2024 · 0 comments

Comments

@simonschaufi
Copy link
Collaborator

Feature: #94622 - New TCA type "category"

https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.4/Feature-94622-NewTCATypeCategory.html

Feature: #94622 - New TCA type "category"

See 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\CMS\Core\Category\CategoryRegistry as well as the
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility->makeCategorizable(),
which required creating a "TCA overrides" file.

Both, the CategoryRegistry as well as
ExtensionManagementUtility->makeCategorizable() 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 default is manyToMany. All possible values are:

  • oneToOne: Stores the uid of the selected category. When using this
    relationship, maxitems=1 will automatically be added to the column
    configuration
  • oneToMany: Stores the uids of selected categories in a
    comma-separated list
  • manyToMany (default): Uses the intermediate table
    sys_category_record_mm and only stores the categories count on the
    local side. This is the use case, which was previously accomplished
    using ExtensionManagementUtility->makeCategorizable().

This means, the new type can not only be used with
relationship=manyToMany as a replacement for makeCategorizable 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
  • exclusiveKeys: As known from renderType=selectTree
  • treeConfig: As known from renderType=selectTree

It's possible to use TSconfig options, such as removeItems. 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
  • readOnly
  • treeConfig

Note

It's still possible to configure a category tree with type=select
and renderType=selectTree. 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.

Backend, TCA, ext:backend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant