@@ -584,11 +584,22 @@ public function enrichRecordWithRelatedRecords(RecordInterface $record, array $e
584
584
$ this ->identifierFieldName = 'uid ' ;
585
585
switch ($ columnConfiguration ['type ' ]) {
586
586
case 'select ' :
587
+ $ whereClause = '' ;
588
+ if (!empty ($ columnConfiguration ['foreign_table_where ' ])) {
589
+ /** @var ReplaceMarkersService $replaceMarkers */
590
+ $ whereClause = $ columnConfiguration ['foreign_table_where ' ];
591
+ if (false !== strpos ($ whereClause , '# ' )) {
592
+ $ replaceMarkers = GeneralUtility::makeInstance (ReplaceMarkersService::class);
593
+ $ whereClause = QueryHelper::quoteDatabaseIdentifiers ($ this ->localDatabase , $ whereClause );
594
+ $ whereClause = $ replaceMarkers ->replaceMarkers ($ record , $ whereClause , $ propertyName );
595
+ }
596
+ }
587
597
$ relatedRecords = $ this ->fetchRelatedRecordsBySelect (
588
598
$ columnConfiguration ,
589
599
$ record ,
590
600
$ propertyName ,
591
- $ excludedTableNames
601
+ $ excludedTableNames ,
602
+ $ whereClause
592
603
);
593
604
break ;
594
605
case 'inline ' :
@@ -1107,7 +1118,8 @@ protected function fetchRelatedRecordsByFlexForm(
1107
1118
$ column ,
1108
1119
$ excludedTableNames ,
1109
1120
$ config ,
1110
- $ currentFlexFormDatum
1121
+ $ currentFlexFormDatum ,
1122
+ $ key
1111
1123
);
1112
1124
$ records = array_merge ($ records , $ newRecords );
1113
1125
}
@@ -1122,6 +1134,7 @@ protected function fetchRelatedRecordsByFlexForm(
1122
1134
* @param array $exclTables
1123
1135
* @param $config
1124
1136
* @param mixed $flexFormData
1137
+ * @param string $key
1125
1138
*
1126
1139
* @return array
1127
1140
* @throws Exception
@@ -1131,7 +1144,8 @@ protected function getRecordsByFlexFormRelation(
1131
1144
$ column ,
1132
1145
array $ exclTables ,
1133
1146
$ config ,
1134
- $ flexFormData
1147
+ $ flexFormData ,
1148
+ string $ key
1135
1149
): array {
1136
1150
if ($ this ->shouldSkipSearchingForRelatedRecordsByFlexFormProperty ($ record , $ config , $ flexFormData )) {
1137
1151
return [];
@@ -1142,7 +1156,27 @@ protected function getRecordsByFlexFormRelation(
1142
1156
$ recordId = $ record ->getIdentifier ();
1143
1157
switch ($ config ['type ' ]) {
1144
1158
case 'select ' :
1145
- $ records = $ this ->fetchRelatedRecordsBySelect ($ config , $ record , $ flexFormData , $ exclTables , true );
1159
+ $ whereClause = '' ;
1160
+ if (!empty ($ config ['foreign_table_where ' ])) {
1161
+ /** @var ReplaceMarkersService $replaceMarkers */
1162
+ $ whereClause = $ config ['foreign_table_where ' ];
1163
+ if (false !== strpos ($ whereClause , '{# ' )) {
1164
+ $ whereClause = QueryHelper::quoteDatabaseIdentifiers ($ this ->localDatabase , $ whereClause );
1165
+ }
1166
+ if (false !== strpos ($ whereClause , '### ' )) {
1167
+ $ replaceMarkers = GeneralUtility::makeInstance (ReplaceMarkersService::class);
1168
+ $ whereClause = $ replaceMarkers ->replaceFlexFormMarkers ($ record , $ whereClause , $ column , $ key );
1169
+ }
1170
+ }
1171
+
1172
+ $ records = $ this ->fetchRelatedRecordsBySelect (
1173
+ $ config ,
1174
+ $ record ,
1175
+ $ column ,
1176
+ $ exclTables ,
1177
+ $ whereClause ,
1178
+ $ flexFormData
1179
+ );
1146
1180
break ;
1147
1181
case 'inline ' :
1148
1182
$ records = $ this ->fetchRelatedRecordsByInline (
@@ -1501,16 +1535,18 @@ protected function getFileAndPathNames(
1501
1535
* @param RecordInterface $record
1502
1536
* @param string $propertyName
1503
1537
* @param array $excludedTableNames
1504
- * @param bool $overrideIdByRecord
1538
+ * @param string $whereClause
1539
+ * @param mixed $recordIdentifierOverride
1505
1540
*
1506
1541
* @return array
1507
1542
*/
1508
1543
protected function fetchRelatedRecordsBySelect (
1509
1544
array $ columnConfiguration ,
1510
1545
RecordInterface $ record ,
1511
- $ propertyName ,
1546
+ string $ propertyName ,
1512
1547
array $ excludedTableNames ,
1513
- $ overrideIdByRecord = false
1548
+ string $ whereClause ,
1549
+ $ recordIdentifierOverride = null
1514
1550
): array {
1515
1551
$ tableName = $ columnConfiguration ['foreign_table ' ];
1516
1552
$ isL10nPointer = $ propertyName === $ this ->tcaService ->getTransOrigPointerField ($ record ->getTableName ());
@@ -1520,8 +1556,8 @@ protected function fetchRelatedRecordsBySelect(
1520
1556
}
1521
1557
$ records = [];
1522
1558
1523
- if ($ overrideIdByRecord ) {
1524
- $ recordIdentifier = $ propertyName ;
1559
+ if (null !== $ recordIdentifierOverride ) {
1560
+ $ recordIdentifier = $ recordIdentifierOverride ;
1525
1561
} else {
1526
1562
$ recordIdentifier = $ record ->getMergedProperty ($ propertyName );
1527
1563
}
@@ -1531,15 +1567,6 @@ protected function fetchRelatedRecordsBySelect(
1531
1567
if (!empty ($ columnConfiguration ['MM ' ])) {
1532
1568
$ records = $ this ->fetchRelatedRecordsBySelectMm ($ columnConfiguration , $ record , $ excludedTableNames );
1533
1569
} else {
1534
- $ whereClause = '' ;
1535
- if (!empty ($ columnConfiguration ['foreign_table_where ' ])) {
1536
- /** @var ReplaceMarkersService $replaceMarkers */
1537
- $ replaceMarkers = GeneralUtility::makeInstance (ReplaceMarkersService::class);
1538
- $ foreignTblWhere = $ columnConfiguration ['foreign_table_where ' ];
1539
- $ foreignTblWhere = QueryHelper::quoteDatabaseIdentifiers ($ this ->localDatabase , $ foreignTblWhere );
1540
- $ whereClause = $ replaceMarkers ->replaceMarkers ($ record , $ foreignTblWhere , $ propertyName );
1541
- }
1542
-
1543
1570
$ uidArray = [];
1544
1571
1545
1572
if (MathUtility::canBeInterpretedAsInteger ($ recordIdentifier )) {
0 commit comments