$tableConfig) { // What fields can have a relational connection to other tables? foreach ($tableConfig['columns'] ?? [] as $fieldName => $fieldConfig) { $fieldConfig = $fieldConfig['config'] ?? null; if (!in_array($fieldConfig['type'] ?? '', ['select', 'group', 'inline', 'file', 'category', 'flex'], true)) { continue; } if ($fieldConfig['type'] === 'flex') { $this->addRelationsForFlexFieldToRelationMap($table, $tableConfig, $fieldName, $relationMap); } else { $relationMap->add($table, $fieldName, $fieldConfig); } } } return $relationMap; } /** * Adds relations for a flex field to the relation map. * Note: Inside a section, it is not possible to add a field with a relation (type 'inline', 'file', 'folder', 'group', 'category'). * See TcaFlexProcess class for details. */ private function addRelationsForFlexFieldToRelationMap(string $tableName, array $tableConfig, string $fieldName, RelationMap $relationMap): void { foreach (array_merge(['default'], array_keys($tableConfig['types'] ?? [])) as $recordType) { try { $dataStructure = $this->flexFormTools->parseDataStructureByIdentifier(json_encode([ 'type' => 'tca', 'tableName' => $tableName, 'fieldName' => $fieldName, 'dataStructureKey' => $recordType, ]), $tableConfig); } catch (InvalidTcaSchemaException|InvalidIdentifierException|InvalidDataStructureException) { // Skip default on error continue; } if (!is_array($dataStructure['sheets'] ?? null)) { continue; } foreach ($dataStructure['sheets'] as $sheetIdentifier => $sheet) { foreach ($sheet['ROOT']['el'] as $flexFieldName => $flexFieldConfig) { $fieldIdentifier = $sheetIdentifier . '/' . $flexFieldName; $relationMap->add($tableName, $fieldName, $flexFieldConfig['config'] ?? [], $fieldIdentifier); } } } } }