Manipulate TCA foreign_table_where for sys_category to show only from certain parents

Viewed 35

In tt_address I only want to show sys_categories that have a certain parent category. In my tt_address tca override I tried to prepend to the existing where clause.

$GLOBALS['TCA']['tt_address']['columns']['categories']['config']['foreign_table_where'] = ' AND sys_category.parent IN (14,15,16,67,68) '. $GLOBALS['TCA']['tt_address']['columns']['categories']['config']['foreign_table_where'];

as well as

$GLOBALS['TCA']['tt_address']['columns']['categories']['config']['foreign_table_where'] = ' AND sys_category.parent > 13 '. $GLOBALS['TCA']['tt_address']['columns']['categories']['config']['foreign_table_where'];

Both show up correctly in the TCA in the backend configuration view but they both lead to an empty category field in the tt_address entries. I get no errors so I am at a loss why this might be. Any ideas or maybe better approaches are greatly appreciated.

1 Answers

After some more testing it seems the most parent category (aka 0) must be in the list to make this work. However that beats the whole purpose. So I have changed the query to check for the pid where the categories are saved. That works just fine for my specific usecase.

$GLOBALS['TCA']['tt_address']['columns']['categories']['config']['foreign_table_where'] = ' AND sys_category.pid IN (283,284,285,294,295)'. $GLOBALS['TCA']['tt_address']['columns']['categories']['config']['foreign_table_where'];

Still, if someone has an idea on how to solve it via the parent cats I would be happy to hear about that.

Related