Bug #71256

CategoryRegistry::isRegistered() is broken by TCA caching.

Added by Klaus Bitto about 6 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Categorization API
Target version:
-
Start date:
2015-11-02
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Situation: Adding a custom category field to e.g. table 'pages' in Configuration/TCA/Overrides/pages.php.
The categorized field should be in the TCA cache, therefore ext_tables.php would be the wrong place to add the category field.

The following will only work right after clearing system caches:

        if(!CategoryRegistry::getInstance()->isRegistered($tableName, $fieldName)) {

            throw new \InvalidArgumentException($tableName . '.' . $fieldName . ' is no registered category field.');
        }

Instead, a workaround is needed:


        /**

         * Note: CategoryRegistry::getInstance()->isRegistered($tableName, $fieldName) only works after clearing

         *       System Cache, since otherwise TCA is cached and makeCategorizable calls are ommitted during boot.

         *       To use defined categorized fields from cache, we need to analyze TCA directly.

         */

        if(!isset($GLOBALS['TCA'][$tableName]['columns'][$fieldName])

            || $GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config']['foreign_table'] != 'sys_category') {

            throw new \InvalidArgumentException($tableName . '.' . $fieldName . ' is no registered category field in TCA.');

         }

CategoryRegistry::getInstance()->isRegistered($tableName, $fieldName) should always return TRUE if a categorized field has been registered and FALSE if no such field exists in TCA -- not only if makeCategorizable has been called during bootup, adding categories as non-cached TCA parts.

Also available in: Atom PDF