TYPO3 后端只能选择一个类别

TYPO3 only one category selectable in backend

我有一条记录,其中有一个名为 type 的字段,该字段使用 TYPO3 类别 API。

基本上我是这样做的:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable(
    'my_ext',
    'my_table_name',
    'type',
    [
        'label' => 'Type',
        'exclude' => false,
        'config' => [
            'eval' => 'required',
        ]
    ]
);

当我编辑这样的记录时,我可以选择任意多个类别。事实上,我希望最终用户只能选择一个。

有没有简单的方法可以做到这一点?

请查看根据需要解释 how to make a table categorizable. Here you can see that the 4th parameter of ExtensionManagementUtility::makeCategorizable() itself does not allow for full TCA overrides, but you can use its fieldConfiguration subsection to set maxitems 的文档:

    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable(
        'my_ext',
        'my_table_name',
        'type',
        [
            'label' => 'Type',
            'exclude' => false,
            'fieldConfiguration' => [
                'eval' => 'required',
                'maxitems' => 1,
            ],
        ]
    );