diff --git a/typo3/sysext/backend/Classes/Controller/FormSelectTreeAjaxController.php b/typo3/sysext/backend/Classes/Controller/FormSelectTreeAjaxController.php index 2b5715bfb95d..a75dd0b5a0a7 100644 --- a/typo3/sysext/backend/Classes/Controller/FormSelectTreeAjaxController.php +++ b/typo3/sysext/backend/Classes/Controller/FormSelectTreeAjaxController.php @@ -103,41 +103,40 @@ public function fetchDataAction(ServerRequestInterface $request): ResponseInterf ], ]; } - } else { - if (isset($dataStructure['sheets'][$flexFormSheetName]['ROOT'] - ['el'][$flexFormFieldName] - ['el'][$flexFormContainerName] - ['el'][$flexFormContainerFieldName]) - ) { - // If this is a tree in a section container that has just been added by the FlexFormAjaxController - // "new container" action, then this container is not yet persisted, so we need to trigger the - // TcaFlexProcess data provider again to prepare the DS and databaseRow of that container. - if ($flexFormSectionContainerIsNew) { - $flexSectionContainerPreparation = [ - 'flexFormSheetName' => $flexFormSheetName, - 'flexFormFieldName' => $flexFormFieldName, - 'flexFormContainerName' => $flexFormContainerName, - 'flexFormContainerIdentifier' => $flexFormContainerIdentifier, - ]; - } - // Now restrict the data structure to our tree element only - $dataStructure = [ - 'sheets' => [ - $flexFormSheetName => [ - 'ROOT' => [ - 'type' => 'array', - 'el' => [ - $flexFormFieldName => [ - 'section' => 1, - 'type' => 'array', - 'el' => [ - $flexFormContainerName => [ - 'el' => [ - $flexFormContainerFieldName => $dataStructure['sheets'][$flexFormSheetName]['ROOT'] - ['el'][$flexFormFieldName] - ['el'][$flexFormContainerName] - ['el'][$flexFormContainerFieldName] - ], + } elseif (isset($dataStructure['sheets'][$flexFormSheetName]['ROOT'] + ['el'][$flexFormFieldName] + ['el'][$flexFormContainerName] + ['el'][$flexFormContainerFieldName]) + ) { + // If this is a tree in a section container that has just been added by the FlexFormAjaxController + // "new container" action, then this container is not yet persisted, so we need to trigger the + // TcaFlexProcess data provider again to prepare the DS and databaseRow of that container. + if ($flexFormSectionContainerIsNew) { + $flexSectionContainerPreparation = [ + 'flexFormSheetName' => $flexFormSheetName, + 'flexFormFieldName' => $flexFormFieldName, + 'flexFormContainerName' => $flexFormContainerName, + 'flexFormContainerIdentifier' => $flexFormContainerIdentifier, + ]; + } + // Now restrict the data structure to our tree element only + $dataStructure = [ + 'sheets' => [ + $flexFormSheetName => [ + 'ROOT' => [ + 'type' => 'array', + 'el' => [ + $flexFormFieldName => [ + 'section' => 1, + 'type' => 'array', + 'el' => [ + $flexFormContainerName => [ + 'type' => 'array', + 'el' => [ + $flexFormContainerFieldName => $dataStructure['sheets'][$flexFormSheetName]['ROOT'] + ['el'][$flexFormFieldName] + ['el'][$flexFormContainerName] + ['el'][$flexFormContainerFieldName] ], ], ], @@ -145,8 +144,8 @@ public function fetchDataAction(ServerRequestInterface $request): ResponseInterf ], ], ], - ]; - } + ], + ]; } $processedTca['columns'][$fieldName]['config']['ds'] = $dataStructure; $processedTca['columns'][$fieldName]['config']['dataStructureIdentifier'] = $dataStructureIdentifier; diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaFlexPrepareTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaFlexPrepareTest.php index bc7d05ab69a3..1d9593365e21 100644 --- a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaFlexPrepareTest.php +++ b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaFlexPrepareTest.php @@ -285,4 +285,224 @@ public function addDataInitializesDatabaseRowValueIfNoDataStringIsGiven() self::assertEquals($expected, (new TcaFlexPrepare())->addData($input)); } + + /** + * @test + */ + public function addDataSetsParsedDataStructureArrayRecursive(): void + { + $input = [ + 'systemLanguageRows' => [], + 'tableName' => 'aTableName', + 'databaseRow' => [ + 'aField' => [ + 'data' => [], + 'meta' => [], + ], + ], + 'processedTca' => [ + 'columns' => [ + 'aField' => [ + 'config' => [ + 'type' => 'flex', + 'ds' => [ + 'default' => ' + + + + + array + + selectTree + + + + + + select_tree_1 description + + select + selectTree + + + + + + + + + array + + section + + + + section_1 + array +
1
+ + + array + container_1 + + + + + select_tree_2 description + + select + selectTree + + + + + + +
+
+
+
+
+
+ ', + ], + ], + ], + ], + ], + ]; + + $GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns']; + + $expected = $input; + $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier'] + = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}'; + + $expected['processedTca']['columns']['aField']['config']['ds'] = [ + 'sheets' => [ + 'sSection' => [ + 'ROOT' => [ + 'type' => 'array', + 'sheetTitle' => 'section', + 'el' => [ + 'section_1' => [ + 'title' => 'section_1', + 'type' => 'array', + 'section' => '1', + 'el' => [ + 'container_1' => [ + 'type' => 'array', + 'title' => 'container_1', + 'el' => [ + 'select_tree_2' => [ + 'label' => 'select_tree_2', + 'description' => 'select_tree_2 description', + 'config' => [ + 'type' => 'select', + 'renderType' => 'selectTree' + ] + ] + ] + ] + ] + ] + ], + ], + ], + 'sTree' => [ + 'ROOT' => [ + 'type' => 'array', + 'sheetTitle' => 'selectTree', + 'el' => [ + 'select_tree_1' => [ + 'label' => 'select_tree_1', + 'description' => 'select_tree_1 description', + 'config' => [ + 'type' => 'select', + 'renderType' => 'selectTree' + ] + ] + ] + ] + ], + ], + 'meta' => [], + ]; + + self::assertEquals($expected, (new TcaFlexPrepare())->addData($input)); + } + + /** + * Test of the data provider when called for a section with already + * resolved flex form, e.g. in an ajax request (tcaSelectTreeAjaxFieldData), + * which got "reduced to the relevant element only". + * + * @test + */ + public function addDataMigratesResolvedFlexformTca(): void + { + $columnConfig = [ + 'label' => 'select_section_1', + 'description' => 'select_section_1 description', + 'config' => [ + 'type' => 'select' + ] + ]; + + $input = [ + 'systemLanguageRows' => [], + 'tableName' => 'aTableName', + 'databaseRow' => [ + 'aField' => [ + 'data' => [], + 'meta' => [], + ], + ], + 'processedTca' => [ + 'columns' => [ + 'aField' => [ + 'config' => [ + 'type' => 'flex', + 'ds' => [ + 'sheets' => [ + 'sSection' => [ + 'ROOT' => [ + 'type' => 'array', + 'el' => [ + 'section_1' => [ + 'section' => 1, + 'type' => 'array', + 'el' => [ + 'container_1' => [ + 'type' => 'array', + 'el' => [ + 'select_section_1' => [ + 'TCEforms' => $columnConfig + ] + ] + ] + ] + ] + ] + ] + ] + ] + ], + 'dataStructureIdentifier' => '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}' + ], + ], + ], + ], + ]; + + $expected = $input; + $expected['processedTca']['columns']['aField']['config']['ds']['meta'] = []; + $expected['processedTca']['columns']['aField']['config']['ds'] + ['sheets']['sSection']['ROOT']['el'] + ['section_1']['el'] + ['container_1']['el'] + ['select_section_1'] = $columnConfig; + + self::assertEquals($expected, (new TcaFlexPrepare())->addData($input)); + } }