43 foreach ($result[
'processedTca'][
'columns'] as $fieldName => $fieldConfig) {
44 if (empty($fieldConfig[
'config'][
'type']) || $fieldConfig[
'config'][
'type'] !==
'flex') {
47 if (!isset($result[
'processedTca'][
'columns'][$fieldName][
'config'][
'dataStructureIdentifier'])) {
48 throw new \RuntimeException(
49 'Data structure identifier must be set, typically by executing TcaFlexPrepare data provider before',
54 $dataStructureIdentifier = $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'dataStructureIdentifier'];
56 $pageTsConfigOfFlex = $this->
getPageTsOfFlex($result, $fieldName, $simpleDataStructureIdentifier);
64 if (!empty($result[
'flexSectionContainerPreparation'])) {
83 $dataStructure = $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'];
84 if (!isset($dataStructure[
'sheets']) || !is_array($dataStructure[
'sheets'])) {
87 foreach ($dataStructure[
'sheets'] as $dataStructureSheetName => $dataStructureSheetDefinition) {
88 if (!isset($dataStructureSheetDefinition[
'ROOT'][
'el']) || !is_array($dataStructureSheetDefinition[
'ROOT'][
'el'])) {
91 $dataStructureFields = $dataStructureSheetDefinition[
'ROOT'][
'el'];
92 foreach ($dataStructureFields as $dataStructureFieldName => $dataStructureFieldDefinition) {
93 if (isset($dataStructureFieldDefinition[
'type']) && $dataStructureFieldDefinition[
'type'] ===
'array'
94 && isset($dataStructureFieldDefinition[
'section']) && (
string)$dataStructureFieldDefinition[
'section'] ===
'1'
96 if (isset($dataStructureFieldDefinition[
'el']) && is_array($dataStructureFieldDefinition[
'el'])) {
97 foreach ($dataStructureFieldDefinition[
'el'] as $containerName => $containerConfiguration) {
98 if (isset($containerConfiguration[
'el']) && is_array($containerConfiguration[
'el'])) {
99 foreach ($containerConfiguration[
'el'] as $singleFieldName => $singleFieldConfiguration) {
101 if (isset($singleFieldConfiguration[
'config'][
'type']) && $singleFieldConfiguration[
'config'][
'type'] ===
'inline') {
102 throw new \UnexpectedValueException(
103 'Invalid flex form data structure on field name "' . $fieldName .
'" with element "' . $singleFieldName .
'"'
104 .
' in section container "' . $containerName .
'": Nesting inline elements in flex form'
105 .
' sections is not allowed.',
111 if (is_array($singleFieldConfiguration)
112 && isset($singleFieldConfiguration[
'type']) && $singleFieldConfiguration[
'type'] ===
'array'
113 && isset($singleFieldConfiguration[
'section']) && (
string)$singleFieldConfiguration[
'section'] ===
'1'
115 throw new \UnexpectedValueException(
116 'Invalid flex form data structure on field name "' . $fieldName .
'" with element "' . $singleFieldName .
'"'
117 .
' in section container "' . $containerName .
'": Nesting sections in container elements'
118 .
' sections is not allowed.',
126 if (is_array($singleFieldConfiguration)
127 && isset($singleFieldConfiguration[
'config'][
'type'])
128 && ($singleFieldConfiguration[
'config'][
'type'] ===
'group' || $singleFieldConfiguration[
'config'][
'type'] ===
'select')
129 && array_key_exists(
'MM', $singleFieldConfiguration[
'config'])
131 throw new \UnexpectedValueException(
132 'Invalid flex form data structure on field name "' . $fieldName .
'" with element "' . $singleFieldName .
'"'
133 .
' in section container "' . $containerName .
'": Nesting select and group elements in flex form'
134 .
' sections is not allowed with MM relations.',
142 } elseif (isset($dataStructureFieldDefinition[
'type']) xor isset($dataStructureFieldDefinition[
'section'])) {
144 throw new \UnexpectedValueException(
145 'Broken data structure on field name ' . $fieldName .
'. section without type or vice versa is not allowed',
190 $identifierArray = json_decode($dataStructureIdentifier,
true);
191 $simpleDataStructureIdentifier =
'default';
192 if (isset($identifierArray[
'type']) && $identifierArray[
'type'] ===
'tca' && isset($identifierArray[
'dataStructureKey'])) {
193 $explodedKey = explode(
',', $identifierArray[
'dataStructureKey']);
194 if (!empty($explodedKey[1]) && $explodedKey[1] !==
'list' && $explodedKey[1] !==
'*') {
195 $simpleDataStructureIdentifier = $explodedKey[1];
196 } elseif (!empty($explodedKey[0]) && $explodedKey[0] !==
'list' && $explodedKey[0] !==
'*') {
197 $simpleDataStructureIdentifier = $explodedKey[0];
200 return $simpleDataStructureIdentifier;
213 $table = $result[
'tableName'];
215 if (!empty($result[
'pageTsConfig'][
'TCEFORM.'][$table .
'.'][$fieldName .
'.'][$flexIdentifier .
'.'])
216 && is_array($result[
'pageTsConfig'][
'TCEFORM.'][$table .
'.'][$fieldName .
'.'][$flexIdentifier .
'.'])) {
217 $pageTs = $result[
'pageTsConfig'][
'TCEFORM.'][$table .
'.'][$fieldName .
'.'][$flexIdentifier .
'.'];
233 $modifiedDataStructure = $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'];
235 if (isset($modifiedDataStructure[
'sheets']) && is_array($modifiedDataStructure[
'sheets'])) {
237 foreach ($modifiedDataStructure[
'sheets'] as $sheetName => $sheetStructure) {
238 if (isset($pageTsConfig[$sheetName .
'.']) && is_array($pageTsConfig[$sheetName .
'.'])) {
239 $pageTsOfSheet = $pageTsConfig[$sheetName .
'.'];
242 if (!empty($pageTsOfSheet[
'disabled'])) {
243 unset($modifiedDataStructure[
'sheets'][$sheetName]);
253 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'] = $modifiedDataStructure;
268 $dataStructure = $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'];
270 if ($backendUser->isAdmin() || !isset($dataStructure[
'sheets']) || !is_array($dataStructure[
'sheets'])) {
274 $userNonExcludeFields = GeneralUtility::trimExplode(
',', $backendUser->groupData[
'non_exclude_fields']);
275 $excludeFieldsPrefix = $result[
'tableName'] .
':' . $fieldName .
';' . $flexIdentifier .
';';
276 $nonExcludeFields = [];
277 foreach ($userNonExcludeFields as $userNonExcludeField) {
278 if (strpos($userNonExcludeField, $excludeFieldsPrefix) !==
false) {
279 $exploded = explode(
';', $userNonExcludeField);
280 $sheetName = $exploded[2];
281 $allowedFlexFieldName = $exploded[3];
282 $nonExcludeFields[$sheetName][$allowedFlexFieldName] =
true;
285 foreach ($dataStructure[
'sheets'] as $sheetName => $sheetDefinition) {
286 if (!isset($sheetDefinition[
'ROOT'][
'el']) || !is_array($sheetDefinition[
'ROOT'][
'el'])) {
289 foreach ($sheetDefinition[
'ROOT'][
'el'] as $flexFieldName => $fieldDefinition) {
290 if (!empty($fieldDefinition[
'exclude']) && !isset($nonExcludeFields[$sheetName][$flexFieldName])) {
291 unset($result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'][
'sheets'][$sheetName][
'ROOT'][
'el'][$flexFieldName]);
309 $dataStructure = $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'];
310 if (!isset($dataStructure[
'sheets']) || !is_array($dataStructure[
'sheets'])) {
313 foreach ($dataStructure[
'sheets'] as $sheetName => $sheetDefinition) {
314 if (!isset($sheetDefinition[
'ROOT'][
'el']) || !is_array($sheetDefinition[
'ROOT'][
'el'])
315 || !isset($pageTsConfig[$sheetName .
'.'])) {
318 foreach ($sheetDefinition[
'ROOT'][
'el'] as $flexFieldName => $fieldDefinition) {
319 if (!empty($pageTsConfig[$sheetName .
'.'][$flexFieldName .
'.'][
'disabled'])) {
320 unset($result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'][
'sheets'][$sheetName][
'ROOT'][
'el'][$flexFieldName]);
343 $dataStructure = $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'];
344 $dataValues = $result[
'databaseRow'][$fieldName];
345 $tableName = $result[
'tableName'];
347 if (!isset($dataStructure[
'sheets']) || !is_array($dataStructure[
'sheets'])) {
351 $formDataGroup = GeneralUtility::makeInstance(FlexFormSegment::class);
352 $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
354 foreach ($dataStructure[
'sheets'] as $dataStructureSheetName => $dataStructureSheetDefinition) {
355 if (!isset($dataStructureSheetDefinition[
'ROOT'][
'el']) || !is_array($dataStructureSheetDefinition[
'ROOT'][
'el'])) {
358 $dataStructureFields = $dataStructureSheetDefinition[
'ROOT'][
'el'];
361 $pageTsConfig[
'TCEFORM.'][$tableName .
'.'] = [];
362 if (isset($pageTsConfig[$dataStructureSheetName .
'.']) && is_array($pageTsConfig[$dataStructureSheetName .
'.'])) {
363 $pageTsConfig[
'TCEFORM.'][$tableName .
'.'] = $pageTsConfig[$dataStructureSheetName .
'.'];
369 $tcaEditColumns = [];
372 'uid' => $result[
'databaseRow'][
'uid'],
374 foreach ($dataStructureFields as $dataStructureFieldName => $dataStructureFieldDefinition) {
375 if (isset($dataStructureFieldDefinition[
'type']) && $dataStructureFieldDefinition[
'type'] ===
'array'
376 && isset($dataStructureFieldDefinition[
'section']) && (
string)$dataStructureFieldDefinition[
'section'] ===
'1'
385 if (isset($dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureFieldName][
'el'])
386 && is_array($dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureFieldName][
'el'])
388 $containerValueArray = $dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureFieldName][
'el'];
389 $containerDataStructuresPerContainer = [];
390 foreach ($containerValueArray as $aContainerIdentifier => $aContainerArray) {
391 if (is_array($aContainerArray)) {
392 foreach ($aContainerArray as $aContainerName => $aContainerElementArray) {
393 if ($aContainerName ===
'_TOGGLE') {
397 if (!isset($dataStructureFields[$dataStructureFieldName][
'el'][$aContainerName])) {
401 $vanillaContainerDataStructure = $dataStructureFields[$dataStructureFieldName][
'el'][$aContainerName];
406 'uid' => $result[
'databaseRow'][
'uid'],
408 foreach ($vanillaContainerDataStructure[
'el'] as $singleFieldName => $singleFieldConfiguration) {
410 $singleFieldValueArray = [];
411 if (isset($aContainerElementArray[
'el'][$singleFieldName])
412 && is_array($aContainerElementArray[
'el'][$singleFieldName])
414 $singleFieldValueArray = $aContainerElementArray[
'el'][$singleFieldName];
417 if (array_key_exists(
'vDEF', $singleFieldValueArray)) {
418 $valueArray[$singleFieldName] = $singleFieldValueArray[
'vDEF'];
420 $newColumns[$singleFieldName] = $singleFieldConfiguration;
422 $editColumns[$singleFieldName] = $singleFieldConfiguration;
425 $inputToFlexFormSegment = [
426 'tableName' => $result[
'tableName'],
429 'pageTsConfig' => [],
430 'databaseRow' => $valueArray,
435 'selectTreeCompileItems' => $result[
'selectTreeCompileItems'],
436 'flexParentDatabaseRow' => $result[
'databaseRow'],
437 'effectivePid' => $result[
'effectivePid'],
440 if (!empty($newColumns)) {
447 $inputToFlexFormSegment[
'command'] =
'new';
448 $inputToFlexFormSegment[
'processedTca'][
'columns'] = $newColumns;
449 $flexSegmentResult = $formDataCompiler->compile($inputToFlexFormSegment);
450 foreach ($newColumns as $singleFieldName => $_) {
452 $valueArray[$singleFieldName] = $flexSegmentResult[
'databaseRow'][$singleFieldName];
456 if (!empty($editColumns)) {
457 $inputToFlexFormSegment[
'command'] =
'edit';
458 $inputToFlexFormSegment[
'processedTca'][
'columns'] = $editColumns;
459 $flexSegmentResult = $formDataCompiler->compile($inputToFlexFormSegment);
460 foreach ($editColumns as $singleFieldName => $_) {
461 $result[
'databaseRow'][$fieldName]
462 [
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureFieldName]
463 [
'el'][$aContainerIdentifier][$aContainerName][
'el'][$singleFieldName][
'vDEF']
464 = $flexSegmentResult[
'databaseRow'][$singleFieldName];
465 $containerDataStructuresPerContainer[$aContainerIdentifier] = $vanillaContainerDataStructure;
466 $containerDataStructuresPerContainer[$aContainerIdentifier][
'el'] = $flexSegmentResult[
'processedTca'][
'columns'];
473 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
474 [
'sheets'][$dataStructureSheetName][
'ROOT'][
'el']
475 [$dataStructureFieldName][
'children'] = $containerDataStructuresPerContainer;
478 $result[
'databaseRow'][$fieldName]
479 [
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureFieldName][
'el'] = [];
481 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
482 [
'sheets'][$dataStructureSheetName][
'ROOT'][
'el']
483 [$dataStructureFieldName][
'children'] = [];
487 if (isset($dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureFieldName])
488 && array_key_exists(
'vDEF', $dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureFieldName])
490 $tcaEditColumns[$dataStructureFieldName] = $dataStructureFieldDefinition;
491 $tcaValueArray[$dataStructureFieldName] = $dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureFieldName][
'vDEF'];
493 $tcaNewColumns[$dataStructureFieldName] = $dataStructureFieldDefinition;
499 $inputToFlexFormSegment = [
500 'tableName' => $result[
'tableName'],
502 'pageTsConfig' => $pageTsConfig,
503 'databaseRow' => $tcaValueArray,
508 'flexParentDatabaseRow' => $result[
'databaseRow'],
510 'selectTreeCompileItems' => $result[
'selectTreeCompileItems'],
511 'effectivePid' => $result[
'effectivePid'],
514 if (!empty($tcaNewColumns)) {
516 $inputToFlexFormSegment[
'command'] =
'new';
517 $inputToFlexFormSegment[
'processedTca'][
'columns'] = $tcaNewColumns;
518 $flexSegmentResult = $formDataCompiler->compile($inputToFlexFormSegment);
520 foreach ($tcaNewColumns as $dataStructureFieldName => $_) {
522 if (array_key_exists($dataStructureFieldName, $flexSegmentResult[
'databaseRow'])) {
523 $result[
'databaseRow'][$fieldName]
524 [
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureFieldName][
'vDEF']
525 = $flexSegmentResult[
'databaseRow'][$dataStructureFieldName];
528 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
529 [
'sheets'][$dataStructureSheetName][
'ROOT'][
'el'][$dataStructureFieldName]
530 = $flexSegmentResult[
'processedTca'][
'columns'][$dataStructureFieldName];
534 if (!empty($tcaEditColumns)) {
535 $inputToFlexFormSegment[
'command'] =
'edit';
536 $inputToFlexFormSegment[
'processedTca'][
'columns'] = $tcaEditColumns;
537 $flexSegmentResult = $formDataCompiler->compile($inputToFlexFormSegment);
539 foreach ($tcaEditColumns as $dataStructureFieldName => $_) {
541 if (array_key_exists($dataStructureFieldName, $flexSegmentResult[
'databaseRow'])) {
542 $result[
'databaseRow'][$fieldName]
543 [
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureFieldName][
'vDEF']
544 = $flexSegmentResult[
'databaseRow'][$dataStructureFieldName];
547 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
548 [
'sheets'][$dataStructureSheetName][
'ROOT'][
'el'][$dataStructureFieldName]
549 = $flexSegmentResult[
'processedTca'][
'columns'][$dataStructureFieldName];
566 $flexSectionContainerPreparation = $result[
'flexSectionContainerPreparation'];
567 $flexFormSheetName = $flexSectionContainerPreparation[
'flexFormSheetName'];
568 $flexFormFieldName = $flexSectionContainerPreparation[
'flexFormFieldName'];
569 $flexFormContainerName = $flexSectionContainerPreparation[
'flexFormContainerName'];
570 $flexFormContainerIdentifier = $flexSectionContainerPreparation[
'flexFormContainerIdentifier'];
572 $containerConfiguration = $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
573 [
'sheets'][$flexFormSheetName][
'ROOT'][
'el'][$flexFormFieldName][
'el'][$flexFormContainerName];
575 if (isset($containerConfiguration[
'el']) && is_array($containerConfiguration[
'el'])) {
576 $formDataGroup = GeneralUtility::makeInstance(FlexFormSegment::class);
577 $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
578 $inputToFlexFormSegment = [
579 'tableName' => $result[
'tableName'],
582 'pageTsConfig' => [],
584 'uid' => $result[
'databaseRow'][
'uid'],
588 'columns' => $containerConfiguration[
'el'],
590 'selectTreeCompileItems' => $result[
'selectTreeCompileItems'],
591 'flexParentDatabaseRow' => $result[
'databaseRow'],
592 'effectivePid' => $result[
'effectivePid'],
594 $flexSegmentResult = $formDataCompiler->compile($inputToFlexFormSegment);
596 foreach ($containerConfiguration[
'el'] as $singleFieldName => $singleFieldConfiguration) {
598 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
599 [
'sheets'][$flexFormSheetName][
'ROOT'][
'el']
600 [$flexFormFieldName][
'children'][$flexFormContainerIdentifier]
601 = $containerConfiguration;
602 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
603 [
'sheets'][$flexFormSheetName][
'ROOT'][
'el']
604 [$flexFormFieldName][
'children'][$flexFormContainerIdentifier][
'el']
605 = $flexSegmentResult[
'processedTca'][
'columns'];
607 $result[
'databaseRow'][$fieldName][
'data'][$flexFormSheetName][
'lDEF']
608 [$flexFormFieldName][
'el']
609 [$flexFormContainerIdentifier][$flexFormContainerName][
'el'][$singleFieldName][
'vDEF']
610 = $flexSegmentResult[
'databaseRow'][$singleFieldName];
628 if (!isset($dataStructure[
'ROOT'][
'el']) || !is_array($dataStructure[
'ROOT'][
'el'])) {
629 return $dataStructure;
632 if (!empty($pageTsOfSheet[
'sheetTitle'])) {
633 $dataStructure[
'ROOT'][
'sheetTitle'] = $pageTsOfSheet[
'sheetTitle'];
636 if (!empty($pageTsOfSheet[
'sheetDescription'])) {
637 $dataStructure[
'ROOT'][
'sheetDescription'] = $pageTsOfSheet[
'sheetDescription'];
640 if (!empty($pageTsOfSheet[
'sheetShortDescr'])) {
641 $dataStructure[
'ROOT'][
'sheetShortDescr'] = $pageTsOfSheet[
'sheetShortDescr'];
644 return $dataStructure;