$fieldConfig) { if (empty($fieldConfig['config']['type']) || $fieldConfig['config']['type'] !== 'flex') { continue; } $result = $this->initializeDataStructure($result, (string)$fieldName); $result = $this->initializeDataValues($result, (string)$fieldName); } return $result; } /** * Fetch / initialize data structure. * * The data structures in ['config']['ds'] is initialized here and the dataStructureIdentifier is set. */ protected function initializeDataStructure(array $result, string $fieldName): array { $dataStructureArray = ['sheets' => ['sDEF' => []]]; if (!isset($result['processedTca']['columns'][$fieldName]['config']['dataStructureIdentifier'])) { try { // Actually ['config']['ds'] might already contain the resolved data structure. However, // since the references value might be a file path and a couple of events exist for flex // form resolving, we nevertheless need to call getDataStructureIdentifier() and // parseDataStructureByIdentifier() here. $schema = $result['tcaSchemata']->get($result['tableName']); $dataStructureIdentifier = $this->flexFormTools->getDataStructureIdentifier( $result['processedTca']['columns'][$fieldName], $result['tableName'], $fieldName, $result['databaseRow'], $schema ); $dataStructureArray = $this->flexFormTools->parseDataStructureByIdentifier($dataStructureIdentifier, $schema); // Add the identifier to TCA to use it later during rendering $result['processedTca']['columns'][$fieldName]['config']['dataStructureIdentifier'] = $dataStructureIdentifier; } catch (InvalidDataStructureException|InvalidIdentifierException|InvalidTcaException|UndefinedSchemaException) { // Skip the data structure if it is invalid } } elseif (is_array($result['processedTca']['columns'][$fieldName]['config']['ds'] ?? false)) { // Data structure has been given from outside $dataStructureArray = $result['processedTca']['columns'][$fieldName]['config']['ds']; } else { // Resolve data structure base on given dataStructureIdentifier try { $dataStructureArray = $this->flexFormTools->parseDataStructureByIdentifier($result['processedTca']['columns'][$fieldName]['config']['dataStructureIdentifier'], $result['tcaSchemata']->get($result['tableName'])); } catch (InvalidDataStructureException|InvalidIdentifierException|InvalidTcaSchemaException|UndefinedSchemaException) { // Skip the data structure if it is invalid } } if (!isset($dataStructureArray['meta']) || !is_array($dataStructureArray['meta'])) { $dataStructureArray['meta'] = []; } // Finally add the resolved data Structure to "ds" $result['processedTca']['columns'][$fieldName]['config']['ds'] = $dataStructureArray; return $result; } /** * Parse / initialize value from xml string to array */ protected function initializeDataValues(array $result, string $fieldName): array { $valueArray = []; if (isset($result['databaseRow'][$fieldName]) && $result['databaseRow'][$fieldName] !== '') { if (is_array($result['databaseRow'][$fieldName])) { $valueArray = $result['databaseRow'][$fieldName]; } else { $valueArray = GeneralUtility::xml2array($result['databaseRow'][$fieldName]); if (!is_array($valueArray)) { $valueArray = []; } } } $valueArray['data'] ??= []; $valueArray['meta'] ??= []; $result['databaseRow'][$fieldName] = $valueArray; return $result; } }