2 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
42 foreach ($result[
'processedTca'][
'columns'] as $fieldName => $fieldConfig) {
43 if (empty($fieldConfig[
'config'][
'type']) || $fieldConfig[
'config'][
'type'] !==
'flex') {
48 $pageTsConfigOfFlex = $this->
getPageTsOfFlex($result, $fieldName, $flexIdentifier);
52 $result = $this->modifyDataStructureAndDataValuesByFlexFormSegmentGroup($result, $fieldName, $pageTsConfigOfFlex);
82 $pointerFields = !empty($result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds_pointerField'])
83 ? $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds_pointerField']
86 $flexformIdentifier = !empty($result[
'databaseRow'][$pointerFields[0]]) ? $result[
'databaseRow'][$pointerFields[0]] :
'';
87 if (!empty($result[
'databaseRow'][$pointerFields[1]])
88 && $result[
'databaseRow'][$pointerFields[1]] !==
'list'
89 && $result[
'databaseRow'][$pointerFields[1]] !==
'*'
91 $flexformIdentifier = $result[
'databaseRow'][$pointerFields[1]];
93 if (empty($flexformIdentifier)) {
94 $flexformIdentifier =
'default';
97 return $flexformIdentifier;
110 $table = $result[
'tableName'];
112 if (!empty($result[
'pageTsConfig'][
'TCEFORM.'][$table .
'.'][$fieldName .
'.'][$flexIdentifier .
'.'])
113 && is_array($result[
'pageTsConfig'][
'TCEFORM.'][$table .
'.'][$fieldName .
'.'][$flexIdentifier .
'.'])) {
114 $pageTs = $result[
'pageTsConfig'][
'TCEFORM.'][$table .
'.'][$fieldName .
'.'][$flexIdentifier .
'.'];
130 $modifiedDataStructure = $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'];
132 if (isset($modifiedDataStructure[
'sheets']) && is_array($modifiedDataStructure[
'sheets'])) {
134 foreach ($modifiedDataStructure[
'sheets'] as $sheetName => $sheetStructure) {
135 if (isset($pageTsConfig[$sheetName .
'.']) && is_array($pageTsConfig[$sheetName .
'.'])) {
136 $pageTsOfSheet = $pageTsConfig[$sheetName .
'.'];
139 if (!empty($pageTsOfSheet[
'disabled'])) {
140 unset($modifiedDataStructure[
'sheets'][$sheetName]);
150 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'] = $modifiedDataStructure;
165 $dataStructure = $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'];
167 if ($backendUser->isAdmin() || !isset($dataStructure[
'sheets']) || !is_array($dataStructure[
'sheets'])) {
172 $excludeFieldsPrefix = $result[
'tableName'] .
':' . $fieldName .
';' . $flexIdentifier .
';';
173 $nonExcludeFields = [];
174 foreach ($userNonExcludeFields as $userNonExcludeField) {
175 if (strpos($userNonExcludeField, $excludeFieldsPrefix) !==
false) {
176 $exploded = explode(
';', $userNonExcludeField);
177 $sheetName = $exploded[2];
178 $allowedFlexFieldName = $exploded[3];
179 $nonExcludeFields[$sheetName][$allowedFlexFieldName] =
true;
182 foreach ($dataStructure[
'sheets'] as $sheetName => $sheetDefinition) {
183 if (!isset($sheetDefinition[
'ROOT'][
'el']) || !is_array($sheetDefinition[
'ROOT'][
'el'])) {
186 foreach ($sheetDefinition[
'ROOT'][
'el'] as $flexFieldName => $fieldDefinition) {
187 if (!empty($fieldDefinition[
'exclude']) && !isset($nonExcludeFields[$sheetName][$flexFieldName])) {
188 unset($result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'][
'sheets'][$sheetName][
'ROOT'][
'el'][$flexFieldName]);
206 $dataStructure = $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'];
207 if (!isset($dataStructure[
'sheets']) || !is_array($dataStructure[
'sheets'])) {
210 foreach ($dataStructure[
'sheets'] as $sheetName => $sheetDefinition) {
211 if (!isset($sheetDefinition[
'ROOT'][
'el']) || !is_array($sheetDefinition[
'ROOT'][
'el'])
212 || !isset($pageTsConfig[$sheetName .
'.'])) {
215 foreach ($sheetDefinition[
'ROOT'][
'el'] as $flexFieldName => $fieldDefinition) {
216 if (!empty($pageTsConfig[$sheetName .
'.'][$flexFieldName .
'.'][
'disabled'])) {
217 unset($result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'][
'sheets'][$sheetName][
'ROOT'][
'el'][$flexFieldName]);
238 protected function modifyDataStructureAndDataValuesByFlexFormSegmentGroup(array $result, $fieldName, $pageTsConfig)
240 $dataStructure = $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds'];
241 $dataValues = $result[
'databaseRow'][$fieldName];
242 $tableName = $result[
'tableName'];
244 if (!isset($dataStructure[
'sheets']) || !is_array($dataStructure[
'sheets'])) {
253 foreach ($dataStructure[
'sheets'] as $dataStructureSheetName => $dataStructureSheetDefinition) {
254 if (!isset($dataStructureSheetDefinition[
'ROOT'][
'el']) || !is_array($dataStructureSheetDefinition[
'ROOT'][
'el'])) {
257 $dataStructureSheetElements = $dataStructureSheetDefinition[
'ROOT'][
'el'];
260 $pageTsConfig[
'TCEFORM.'][$tableName .
'.'] = [];
261 if (isset($pageTsConfig[$dataStructureSheetName .
'.']) && is_array($pageTsConfig[$dataStructureSheetName .
'.'])) {
262 $pageTsConfig[
'TCEFORM.'][$tableName .
'.'] = $pageTsConfig[$dataStructureSheetName .
'.'];
266 $tcaEditColumns = [];
268 'uid' => $result[
'databaseRow'][
'uid'],
270 foreach ($dataStructureSheetElements as $dataStructureSheetElementName => $dataStructureSheetElementDefinition) {
271 if (isset($dataStructureSheetElementDefinition[
'type']) && $dataStructureSheetElementDefinition[
'type'] ===
'array'
272 && isset($dataStructureSheetElementDefinition[
'section']) && (
string)$dataStructureSheetElementDefinition[
'section'] ===
'1'
277 if (isset($dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName][
'el'])
278 && is_array($dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName][
'el'])
280 $containerArray = $dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName][
'el'];
281 foreach ($containerArray as $aContainerNumber => $aContainerArray) {
282 if (is_array($aContainerArray)) {
283 foreach ($aContainerArray as $aContainerName => $aContainerElementArray) {
284 if ($aContainerName ===
'_TOGGLE') {
288 if (!isset($dataStructureSheetElements[$dataStructureSheetElementName][
'el'][$aContainerName])) {
296 'uid' => $result[
'databaseRow'][
'uid'],
298 foreach ($dataStructureSheetElements[$dataStructureSheetElementName][
'el'][$aContainerName][
'el'] as $singleFieldName => $singleFieldConfiguration) {
300 $singleFieldValueArray = [];
301 if (isset($aContainerElementArray[
'el'][$singleFieldName])
302 && is_array($aContainerElementArray[
'el'][$singleFieldName])
304 $singleFieldValueArray = $aContainerElementArray[
'el'][$singleFieldName];
307 if (array_key_exists(
'vDEF', $singleFieldValueArray)) {
308 $editColumns[$singleFieldName] = $singleFieldConfiguration;
309 $valueArray[$singleFieldName] = $singleFieldValueArray[
'vDEF'];
311 $newColumns[$singleFieldName] = $singleFieldConfiguration;
315 $inputToFlexFormSegment = [
316 'tableName' => $result[
'tableName'],
319 'pageTsConfig' => [],
320 'databaseRow' => $valueArray,
325 'flexParentDatabaseRow' => $result[
'databaseRow'],
328 if (!empty($newColumns)) {
329 $inputToFlexFormSegment[
'command'] =
'new';
330 $inputToFlexFormSegment[
'processedTca'][
'columns'] = $newColumns;
331 $flexSegmentResult = $formDataCompiler->compile($inputToFlexFormSegment);
333 foreach ($newColumns as $singleFieldName => $_) {
335 if (array_key_exists($singleFieldName, $flexSegmentResult[
'databaseRow'])) {
336 $result[
'databaseRow'][$fieldName]
337 [
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName]
338 [
'el'][$aContainerNumber][$aContainerName][
'el'][$singleFieldName][
'vDEF'] =
339 $flexSegmentResult[
'databaseRow'][$singleFieldName];
343 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
344 [
'sheets'][$dataStructureSheetName][
'ROOT'][
'el']
345 [$dataStructureSheetElementName][
'el'][$aContainerName][
'el'][$singleFieldName] =
346 $flexSegmentResult[
'processedTca'][
'columns'][$singleFieldName];
350 if (!empty($editColumns)) {
351 $inputToFlexFormSegment[
'command'] =
'edit';
352 $inputToFlexFormSegment[
'processedTca'][
'columns'] = $editColumns;
353 $flexSegmentResult = $formDataCompiler->compile($inputToFlexFormSegment);
355 foreach ($editColumns as $singleFieldName => $_) {
357 if (array_key_exists($singleFieldName, $flexSegmentResult[
'databaseRow'])) {
358 $result[
'databaseRow'][$fieldName]
359 [
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName]
360 [
'el'][$aContainerNumber][$aContainerName][
'el'][$singleFieldName][
'vDEF'] =
361 $flexSegmentResult[
'databaseRow'][$singleFieldName];
365 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
366 [
'sheets'][$dataStructureSheetName][
'ROOT'][
'el']
367 [$dataStructureSheetElementName][
'el'][$aContainerName][
'el'][$singleFieldName] =
368 $flexSegmentResult[
'processedTca'][
'columns'][$singleFieldName];
377 $result[
'databaseRow'][$fieldName]
378 [
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName][
'el'] = [];
382 if (isset($dataStructureSheetElements[$dataStructureSheetElementName][
'el']) && is_array($dataStructureSheetElements[$dataStructureSheetElementName][
'el'])) {
383 foreach ($dataStructureSheetElements[$dataStructureSheetElementName][
'el'] as $possibleContainerName => $possibleContainerConfiguration) {
384 if (isset($possibleContainerConfiguration[
'el']) && is_array($possibleContainerConfiguration[
'el'])) {
386 $result[
'databaseRow'][$fieldName]
387 [
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName][
'templateRows']
388 [$possibleContainerName][
'el']
390 foreach ($possibleContainerConfiguration[
'el'] as $singleFieldName => $singleFieldConfiguration) {
391 $inputToFlexFormSegment = [
392 'tableName' => $result[
'tableName'],
394 'pageTsConfig' => [],
396 'uid' => $result[
'databaseRow'][
'uid'],
401 $singleFieldName => $singleFieldConfiguration,
404 'flexParentDatabaseRow' => $result[
'databaseRow'],
406 $flexSegmentResult = $formDataCompiler->compile($inputToFlexFormSegment);
407 if (array_key_exists($singleFieldName, $flexSegmentResult[
'databaseRow'])) {
408 $result[
'databaseRow'][$fieldName]
409 [
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName][
'templateRows']
410 [$possibleContainerName][
'el'][$singleFieldName][
'vDEF']
411 = $flexSegmentResult[
'databaseRow'][$singleFieldName];
413 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
414 [
'sheets'][$dataStructureSheetName][
'ROOT'][
'el'][$dataStructureSheetElementName][
'el']
415 [$possibleContainerName][
'el'][$singleFieldName]
416 = $flexSegmentResult[
'processedTca'][
'columns'][$singleFieldName];
423 }
elseif (isset($dataStructureSheetElementDefinition[
'type']) || isset($dataStructureSheetElementDefinition[
'section'])) {
424 throw new \UnexpectedValueException(
425 'Broken data structure on field name ' . $fieldName .
'. section without type or vice versa is not allowed',
431 if (isset($dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName])
432 && array_key_exists(
'vDEF', $dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName])
434 $tcaEditColumns[$dataStructureSheetElementName] = $dataStructureSheetElementDefinition;
435 $tcaValueArray[$dataStructureSheetElementName] = $dataValues[
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName][
'vDEF'];
437 $tcaNewColumns[$dataStructureSheetElementName] = $dataStructureSheetElementDefinition;
444 $inputToFlexFormSegment = [
446 'tableName' => $result[
'tableName'],
448 'pageTsConfig' => $pageTsConfig,
449 'databaseRow' => $tcaValueArray,
454 'flexParentDatabaseRow' => $result[
'databaseRow'],
457 if (!empty($tcaNewColumns)) {
458 $inputToFlexFormSegment[
'command'] =
'new';
459 $inputToFlexFormSegment[
'processedTca'][
'columns'] = $tcaNewColumns;
460 $flexSegmentResult = $formDataCompiler->compile($inputToFlexFormSegment);
462 foreach ($tcaNewColumns as $dataStructureSheetElementName => $_) {
464 if (array_key_exists($dataStructureSheetElementName, $flexSegmentResult[
'databaseRow'])) {
465 $result[
'databaseRow'][$fieldName]
466 [
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName][
'vDEF']
467 = $flexSegmentResult[
'databaseRow'][$dataStructureSheetElementName];
470 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
471 [
'sheets'][$dataStructureSheetName][
'ROOT'][
'el'][$dataStructureSheetElementName]
472 = $flexSegmentResult[
'processedTca'][
'columns'][$dataStructureSheetElementName];
476 if (!empty($tcaEditColumns)) {
477 $inputToFlexFormSegment[
'command'] =
'edit';
478 $inputToFlexFormSegment[
'processedTca'][
'columns'] = $tcaEditColumns;
479 $flexSegmentResult = $formDataCompiler->compile($inputToFlexFormSegment);
481 foreach ($tcaEditColumns as $dataStructureSheetElementName => $_) {
483 if (array_key_exists($dataStructureSheetElementName, $flexSegmentResult[
'databaseRow'])) {
484 $result[
'databaseRow'][$fieldName]
485 [
'data'][$dataStructureSheetName][
'lDEF'][$dataStructureSheetElementName][
'vDEF']
486 = $flexSegmentResult[
'databaseRow'][$dataStructureSheetElementName];
489 $result[
'processedTca'][
'columns'][$fieldName][
'config'][
'ds']
490 [
'sheets'][$dataStructureSheetName][
'ROOT'][
'el'][$dataStructureSheetElementName]
491 = $flexSegmentResult[
'processedTca'][
'columns'][$dataStructureSheetElementName];
510 if (!isset($dataStructure[
'ROOT'][
'el']) || !is_array($dataStructure[
'ROOT'][
'el'])) {
511 return $dataStructure;
515 if (!empty($pageTsOfSheet[
'sheetTitle'])) {
516 $dataStructure[
'ROOT'][
'sheetTitle'] = $pageTsOfSheet[
'sheetTitle'];
519 if (!empty($pageTsOfSheet[
'sheetDescription'])) {
520 $dataStructure[
'ROOT'][
'sheetDescription'] = $pageTsOfSheet[
'sheetDescription'];
523 if (!empty($pageTsOfSheet[
'sheetShortDescr'])) {
524 $dataStructure[
'ROOT'][
'sheetShortDescr'] = $pageTsOfSheet[
'sheetShortDescr'];
527 return $dataStructure;