Marker ###REC_FIELD_[fieldname]### in TCA config of select type does not work with groups
If you use the marker ###REC_FIELD_[fieldname]### in the "foreign_table_where" of the "config" part of a field, it doesn't work if the referenced fieldname is defined as type "group".
Within the t3lib_BEfunc::exec_foreign_table_where_query function, the marker is replaced with $TSconfig['_THIS_ROW'][fieldname] which does not contain only the database field value but some other information like the displayed text and the database name.
The marker replacement works perfectly, if the refered field is of type select, becaue the $TSconfig['_THIS_ROW'][fieldname] returns in this case the database value of this field.
(issue imported from #M5124)
#1 Updated by Stefan Froemken over 8 years ago
I have the same problem. When I use ###REC_FIELD_pages### in my foreign_table_where it returns this:
But in database I can find 22 only.
That's why I tried it with this workaround:
<foreign_table_where>AND tx_myext_category.pid = (SELECT pages FROM tt_content WHERE uid=###THIS_UID###)</foreign_table_where>
#3 Updated by Stefan Froemken over 8 years ago
I think it is very complicated to solve, because you can add recods of different tables in group fields. To differ them TYPO3 prepends the tablename. Maybe you can solve it with help of a mm-table:
id | parent_id | table | table_id
1 | 23 | pages | 22
I think it will be the best solution, but on the other side it could be a little bit oversized. Let's here some other opinions.
#4 Updated by Franz Koch over 8 years ago
issue still present in 4.5.2.
and it can be solved, because the according method t3lib_becunc::exec_foreign_table_where_query knows the TCA configuration of the processed table/column, so it can detect when it's dealing with a group field. And tablenames only get prepended if you allow relations to more then one table, so that's also not a big issue.
Where I see the issue is that the raw result row passed around get's modified by Typo3 at some point (the raw ID value is replaced by a prepended value including the record label). Found that out in a short debugging session of mentioned method.
edit: sorry, it's not possible to check for the field type, because we don't know the name of the currently rendered table to check the according TCA :(
So either the according parameters have to be added to the method or TYPO3 must not modify the raw values from $TSconfig['_THIS_ROW'] (I wonder why it's done anyway, because it's also causing issues with IRRE having group fields as label - but that's a different story).
#9 Updated by Thomas Goetz 9 months ago
- TYPO3 Version changed from 4.0 to 9
- PHP Version changed from 5.0 to 7.2
2018, TYPO3 9.5 and the error still exists.¶
For the googling people that hope to find a solution here, here is a workaround:
If you try to use e.g. the pages field:
'foreign_table_where' => 'AND tx_myextension_domain_model_myobject.pid = ###REC_FIELD_pages###',
You can achieve the same functionality with a subquery:
'foreign_table_where' => 'AND tx_myextension_domain_model_myobject.pid = (SELECT pages FROM tt_content WHERE uid=###THIS_UID###)',
This fully works expected but(!) subqueries can drastically slow down your your installation.
If there is any other way, I think you should go it.