[TASK] FormEngine: Remove "TCEforms" from sheet level data structure 22/43322/5
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Tue, 15 Sep 2015 10:23:49 +0000 (12:23 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 15 Sep 2015 13:43:45 +0000 (15:43 +0200)
Remove the TCEforms array subkey from the sheet level FlexForm data
structure. This affects the title, descriptions and display conditions
for FlexForm sheets.

Resolves: #69720
Releases: master
Change-Id: I912e513844be9ce034bb878e92c7b17004c0112f
Reviewed-on: http://review.typo3.org/43322
Reviewed-by: Loek Hilgersom <loek@netcoop.nl>
Tested-by: Loek Hilgersom <loek@netcoop.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/Container/FlexFormNoTabsContainer.php
typo3/sysext/backend/Classes/Form/Container/FlexFormTabsContainer.php
typo3/sysext/backend/Classes/Form/FormDataProvider/TcaFlex.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaFlexTest.php

index 1b3d554..8a3ee2d 100644 (file)
@@ -52,9 +52,8 @@ class FlexFormNoTabsContainer extends AbstractContainer {
 
                // Evaluate display condition for this "sheet" if there is one
                $displayConditionResult = TRUE;
-               // @todo: flex provider should remove the TCEforms sub array for display conditions here as well
-               if (!empty($flexFormDataStructureArray['sheets'][$sheetName]['ROOT']['TCEforms']['displayCond'])) {
-                       $displayConditionDefinition = $flexFormDataStructureArray['ROOT']['TCEforms']['displayCond'];
+               if (!empty($flexFormDataStructureArray['sheets'][$sheetName]['ROOT']['displayCond'])) {
+                       $displayConditionDefinition = $flexFormDataStructureArray['ROOT']['displayCond'];
                        $displayConditionResult = $this->evaluateFlexFormDisplayCondition(
                                $displayConditionDefinition,
                                $flexFormRowDataSubPart,
index 4923bad..453226c 100644 (file)
@@ -54,9 +54,8 @@ class FlexFormTabsContainer extends AbstractContainer {
 
                        // Evaluate display condition for this sheet if there is one
                        $displayConditionResult = TRUE;
-                       // @todo: flex provider should remove the TCEforms sub array for display conditions here as well
-                       if (!empty($sheetDataStructure['ROOT']['TCEforms']['displayCond'])) {
-                               $displayConditionDefinition = $sheetDataStructure['ROOT']['TCEforms']['displayCond'];
+                       if (!empty($sheetDataStructure['ROOT']['displayCond'])) {
+                               $displayConditionDefinition = $sheetDataStructure['ROOT']['displayCond'];
                                $displayConditionResult = $this->evaluateFlexFormDisplayCondition(
                                        $displayConditionDefinition,
                                        $flexFormRowData['data'],
@@ -99,10 +98,10 @@ class FlexFormTabsContainer extends AbstractContainer {
                        $childReturn = $this->nodeFactory->create($options)->render();
 
                        $tabsContent[] = array(
-                               'label' => !empty($sheetDataStructure['ROOT']['TCEforms']['sheetTitle']) ? $languageService->sL($sheetDataStructure['ROOT']['TCEforms']['sheetTitle']) : $sheetName,
+                               'label' => !empty($sheetDataStructure['ROOT']['sheetTitle']) ? $languageService->sL($sheetDataStructure['ROOT']['sheetTitle']) : $sheetName,
                                'content' => $childReturn['html'],
-                               'description' => $sheetDataStructure['ROOT']['TCEforms']['sheetDescription'] ? $languageService->sL($sheetDataStructure['ROOT']['TCEforms']['sheetDescription']) : '',
-                               'linkTitle' => $sheetDataStructure['ROOT']['TCEforms']['sheetShortDescr'] ? $languageService->sL($sheetDataStructure['ROOT']['TCEforms']['sheetShortDescr']) : '',
+                               'description' => $sheetDataStructure['ROOT']['sheetDescription'] ? $languageService->sL($sheetDataStructure['ROOT']['sheetDescription']) : '',
+                               'linkTitle' => $sheetDataStructure['ROOT']['sheetShortDescr'] ? $languageService->sL($sheetDataStructure['ROOT']['sheetShortDescr']) : '',
                        );
 
                        $childReturn['html'] = '';
index 1e16706..38786fd 100644 (file)
@@ -179,7 +179,7 @@ class TcaFlex extends AbstractItemProvider implements FormDataProviderInterface
        }
 
        /**
-        * Move ['el']['something']['TCEforms'] to ['el']['something'] recursive
+        * Moves ['el']['something']['TCEforms'] to ['el']['something'] and ['ROOT']['TCEforms'] to ['ROOT'] recursive
         *
         * @param array $structure Given hierarchy
         * @return array Modified hierarchy
@@ -187,6 +187,10 @@ class TcaFlex extends AbstractItemProvider implements FormDataProviderInterface
        protected function removeElementTceFormsRecursive(array $structure) {
                $newStructure = [];
                foreach ($structure as $key => $value) {
+                       if ($key === 'ROOT' && is_array($value) && isset($value['TCEforms'])) {
+                               $value = array_merge($value, $value['TCEforms']);
+                               unset($value['TCEforms']);
+                       }
                        if ($key === 'el' && is_array($value)) {
                                $newSubStructure = [];
                                foreach ($value as $subKey => $subValue) {
@@ -749,15 +753,15 @@ class TcaFlex extends AbstractItemProvider implements FormDataProviderInterface
 
                // Rename sheet (tab)
                if (!empty($pageTsOfSheet['sheetTitle'])) {
-                       $dataStructure['ROOT']['TCEforms']['sheetTitle'] = $pageTsOfSheet['sheetTitle'];
+                       $dataStructure['ROOT']['sheetTitle'] = $pageTsOfSheet['sheetTitle'];
                }
                // Set sheet description (tab)
                if (!empty($pageTsOfSheet['sheetDescription'])) {
-                       $dataStructure['ROOT']['TCEforms']['sheetDescription'] = $pageTsOfSheet['sheetDescription'];
+                       $dataStructure['ROOT']['sheetDescription'] = $pageTsOfSheet['sheetDescription'];
                }
                // Set sheet short description (tab)
                if (!empty($pageTsOfSheet['sheetShortDescr'])) {
-                       $dataStructure['ROOT']['TCEforms']['sheetShortDescr'] = $pageTsOfSheet['sheetShortDescr'];
+                       $dataStructure['ROOT']['sheetShortDescr'] = $pageTsOfSheet['sheetShortDescr'];
                }
 
                return $dataStructure;
index 78be831..ad18ba3 100644 (file)
@@ -245,9 +245,7 @@ class TcaFlexTest extends UnitTestCase {
                                                                ],
                                                        ],
                                                ],
-                                               'TCEforms' => [
-                                                       'sheetTitle' => 'aTitle',
-                                               ],
+                                               'sheetTitle' => 'aTitle',
                                        ],
                                ],
                        ],
@@ -696,9 +694,7 @@ class TcaFlexTest extends UnitTestCase {
                                                                ],
                                                        ],
                                                ],
-                                               'TCEforms' => [
-                                                       'sheetTitle' => 'aTitle',
-                                               ],
+                                               'sheetTitle' => 'aTitle',
                                        ],
                                ],
                        ],
@@ -792,9 +788,7 @@ class TcaFlexTest extends UnitTestCase {
                                                                ],
                                                        ],
                                                ],
-                                               'TCEforms' => [
-                                                       'sheetDescription' => 'aDescription',
-                                               ],
+                                               'sheetDescription' => 'aDescription',
                                        ],
                                ],
                        ],
@@ -888,9 +882,7 @@ class TcaFlexTest extends UnitTestCase {
                                                                ],
                                                        ],
                                                ],
-                                               'TCEforms' => [
-                                                       'sheetDescription' => 'sheetShortDescr',
-                                               ],
+                                               'sheetDescription' => 'sheetShortDescr',
                                        ],
                                ],
                        ],
@@ -980,9 +972,7 @@ class TcaFlexTest extends UnitTestCase {
                                                                ],
                                                        ],
                                                ],
-                                               'TCEforms' => [
-                                                       'sheetDescription' => 'sheetShortDescr',
-                                               ],
+                                               'sheetDescription' => 'sheetShortDescr',
                                        ],
                                ],
                        ],
@@ -3214,4 +3204,124 @@ class TcaFlexTest extends UnitTestCase {
                $this->assertEquals($expectedLanguagesOnElement, $result['processedTca']['columns']['aField']['config']['ds']['meta']['languagesOnElement']);
        }
 
+       /**
+        * @test
+        */
+       public function addDataRemovesTceFormsFromRootArray() {
+               $input = [
+                       'systemLanguageRows' => [],
+                       'databaseRow' => [
+                               'aField' => [
+                                       'data' => [],
+                                       'meta' => [],
+                               ],
+                       ],
+                       'processedTca' => [
+                               'columns' => [
+                                       'aField' => [
+                                               'config' => [
+                                                       'type' => 'flex',
+                                                       'ds' => [
+                                                               'default' => '
+                  <T3DataStructure>
+                    <sheets>
+                      <sDEF>
+                        <ROOT>
+                          <TCEforms>
+                            <sheetTitle>aTitle</sheetTitle>
+                            <sheetDescription>aDescription</sheetDescription>
+                            <sheetShortDescr>aShortDescr</sheetShortDescr>
+                            <displayCond>aDisplayCond</displayCond>
+                          </TCEforms>
+                          <type>array</type>
+                          <el>
+                            <aFlexField>
+                              <TCEforms>
+                                <label>aFlexFieldLabel</label>
+                                <config>
+                                  <type>input</type>
+                                </config>
+                              </TCEforms>
+                            </aFlexField>
+                          </el>
+                        </ROOT>
+                      </sDEF>
+                      <sOther>
+                        <ROOT>
+                          <TCEforms>
+                            <sheetTitle>anotherTitle</sheetTitle>
+                            <displayCond>anotherDisplayCond</displayCond>
+                          </TCEforms>
+                          <type>array</type>
+                          <el>
+                            <bFlexField>
+                              <TCEforms>
+                                <label>bFlexFieldLabel</label>
+                                <config>
+                                  <type>input</type>
+                                </config>
+                              </TCEforms>
+                            </bFlexField>
+                          </el>
+                        </ROOT>
+                      </sOther>
+                    </sheets>
+                  </T3DataStructure>
+                ',
+                                                       ],
+                                               ],
+                                       ],
+                               ],
+                       ],
+               ];
+
+               $expected = $input;
+               $expected['processedTca']['columns']['aField']['config']['ds'] = [
+                       'sheets' => [
+                               'sDEF' => [
+                                       'ROOT' => [
+                                               'type' => 'array',
+                                               'el' => [
+                                                       'aFlexField' => [
+                                                               'label' => 'aFlexFieldLabel',
+                                                               'config' => [
+                                                                       'type' => 'input',
+                                                               ],
+                                                       ],
+                                               ],
+                                               'sheetTitle' => 'aTitle',
+                                               'sheetDescription' => 'aDescription',
+                                               'sheetShortDescr' => 'aShortDescr',
+                                               'displayCond' => 'aDisplayCond',
+                                       ],
+                               ],
+                               'sOther' => [
+                                       'ROOT' => [
+                                               'type' => 'array',
+                                               'el' => [
+                                                       'bFlexField' => [
+                                                               'label' => 'bFlexFieldLabel',
+                                                               'config' => [
+                                                                       'type' => 'input',
+                                                               ],
+                                                       ],
+                                               ],
+                                               'sheetTitle' => 'anotherTitle',
+                                               'displayCond' => 'anotherDisplayCond',
+                                       ],
+                               ],
+                       ],
+                       'meta' => [
+                               'availableLanguageCodes' => [],
+                               'langDisable' => FALSE,
+                               'langChildren' => FALSE,
+                               'languagesOnSheetLevel' => [],
+                               'languagesOnElement' => [
+                                       0 => 'DEF',
+                               ],
+                       ],
+               ];
+
+               $this->assertEquals($expected, $this->subject->addData($input));
+       }
 }