Search code examples
typo3typo3-8.xtypo3-extensions

How to use/link sys_category field in custom model in TYPO3


I am developing an extension in which I am uploading files and for each file upload I need to have one or more categories associated with it.

I have built a custom category model and it shows fine at the backend when creating a record, but I want to show/link the sys_category records instead of my own custom categories.

How do I link that field in my custom model?


Solution

  • If anyone else stumbles upon this, I found the solution from the documentation thanks to @larry-pete.

    Simply add these lines to your ext_tables.php file in your extension folder.

    // Add an extra categories selection field to the pages table
        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable(
            'ext_key',
            'your_table_name',
            'categories',
            array(
                // Set a custom label
                'label' => 'LLL:EXT:ext_key/Resources/Private/Language/locallang.xlf:additional_categories',
                // This field should not be an exclude-field
                'exclude' => FALSE,
                // Override generic configuration, e.g. sort by title rather than by sorting
                'fieldConfiguration' => array(
                    'foreign_table_where' => ' AND sys_category.sys_language_uid IN (-1, 0) ORDER BY sys_category.title ASC',
                ),
                // string (keyword), see TCA reference for details
                'l10n_mode' => 'exclude',
                // list of keywords, see TCA reference for details
                'l10n_display' => 'hideDiff',
            )
        );
    

    Hope it helps someone.