[TASK] FormEngine: optimize overruleTypesArray for inline types 39/43939/8
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 9 Oct 2015 15:25:31 +0000 (17:25 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 9 Oct 2015 16:24:58 +0000 (18:24 +0200)
Provide a dataProvider to override the types section of processedTca
for affected types definitions to unify the handling.

Change-Id: I7e0f412aef05c3ab29005efae62ec176aaa5d4d9
Resolves: #70548
Releases: master
Reviewed-on: http://review.typo3.org/43939
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/backend/Classes/Controller/FormInlineAjaxController.php
typo3/sysext/backend/Classes/Form/FormDataCompiler.php
typo3/sysext/backend/Classes/Form/FormDataProvider/InlineOverruleTypesArray.php [new file with mode: 0644]
typo3/sysext/backend/Classes/Form/FormDataProvider/TcaColumnsProcessShowitem.php
typo3/sysext/backend/Classes/Form/FormDataProvider/TcaInline.php
typo3/sysext/backend/Classes/Form/FormDataProvider/TcaTypesShowitem.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/InlineOverruleTypesArrayTest.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaColumnsProcessShowitemTest.php
typo3/sysext/core/Configuration/DefaultConfiguration.php

index ba3be60..cc79b06 100644 (file)
@@ -104,9 +104,9 @@ class FormInlineAjaxController
         }
 
         $childTableName = $parentConfig['foreign_table'];
-        $overruleTypesArray = [];
+        $inlineOverruleTypesArray = [];
         if (isset($parentConfig['foreign_types'])) {
-            $overruleTypesArray = $parentConfig['foreign_types'];
+            $inlineOverruleTypesArray = $parentConfig['foreign_types'];
         }
         /** @var TcaDatabaseRecord $formDataGroup */
         $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
@@ -117,13 +117,13 @@ class FormInlineAjaxController
             'tableName' => $childTableName,
             'vanillaUid' => $childVanillaUid,
             'inlineFirstPid' => $inlineFirstPid,
-            'overruleTypesArray' => $overruleTypesArray,
+            'inlineOverruleTypesArray' => $inlineOverruleTypesArray,
         ];
         $childData = $formDataCompiler->compile($formDataCompilerInput);
 
         // Set default values for new created records
         // @todo: This should be moved over to some data provider? foreign_record_defaults is currently not handled
-        // @todo: at all, but also not used in core itself. Bonus question: There is "overruleTypesArray", there is this
+        // @todo: at all, but also not used in core itself. Bonus question: There is "inlineOverruleTypesArray", there is this
         // @todo: default setting stuff ... why can't just "all" TCA be overwritten by parent similar to TCA type
         // @todo: related columnsOverrides? Another gem: foreign_selector_fieldTcaOverride overwrites TCA of foreign_selector
         // @todo: depending on parent ...
@@ -542,9 +542,9 @@ class FormInlineAjaxController
     {
         $parentConfig = $parentData['processedTca']['columns'][$parentFieldName]['config'];
         $childTableName = $parentConfig['foreign_table'];
-        $overruleTypesArray = [];
+        $inlineOverruleTypesArray = [];
         if (isset($parentConfig['foreign_types'])) {
-            $overruleTypesArray = $parentConfig['foreign_types'];
+            $inlineOverruleTypesArray = $parentConfig['foreign_types'];
         }
         /** @var TcaDatabaseRecord $formDataGroup */
         $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
@@ -555,7 +555,7 @@ class FormInlineAjaxController
             'tableName' => $childTableName,
             'vanillaUid' => (int)$childUid,
             'inlineFirstPid' => $parentData['inlineFirstPid'],
-            'overruleTypesArray' => $overruleTypesArray,
+            'inlineOverruleTypesArray' => $inlineOverruleTypesArray,
         ];
         // For foreign_selector with useCombination $mainChild is the mm record
         // and $combinationChild is the child-child. For "normal" relations, $mainChild
index 710d9d0..5277085 100644 (file)
@@ -185,7 +185,9 @@ class FormDataCompiler
             // This array of fields will be set as hidden-fields instead of rendered normally!
             // This is used by EditDocumentController to force some field values if set as "overrideVals" in _GP
             'overrideValues' => [],
-
+            // This is the "foreign_types" section of a parent inline configuration that can be used to
+            // overrule the types TCA section of a child element.
+            'inlineOverruleTypesArray' => [],
             // Inline scenario: A localized parent record is handled and localizationMode is set to "select", so inline
             // parents can have localized children. This value is set to TRUE if this array represents a localized child
             // overlay record that has no default language record.
@@ -207,7 +209,7 @@ class FormDataCompiler
             'tabAndInlineStack' => [],
             'inlineData' => [],
             'inlineStructure' => [],
-            'overruleTypesArray' => [],
+
         );
     }
 }
diff --git a/typo3/sysext/backend/Classes/Form/FormDataProvider/InlineOverruleTypesArray.php b/typo3/sysext/backend/Classes/Form/FormDataProvider/InlineOverruleTypesArray.php
new file mode 100644 (file)
index 0000000..eab96b5
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+namespace TYPO3\CMS\Backend\Form\FormDataProvider;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
+
+/**
+ * Add overrule types arrays for inline child records (FAL related)
+ */
+class InlineOverruleTypesArray implements FormDataProviderInterface
+{
+
+    /**
+     * replace types definition for inline children if overruleTypesArray is defined
+     *
+     * @param array $result
+     *
+     * @return array
+     * @throws \UnexpectedValueException
+     */
+    public function addData(array $result)
+    {
+        if (!empty($result['inlineOverruleTypesArray'])) {
+            foreach ($result['inlineOverruleTypesArray'] as $type => $config) {
+                $result['processedTca']['types'][$type] = $config;
+            }
+        }
+
+        return $result;
+    }
+}
index 4a9e283..5c7b7fc 100644 (file)
@@ -47,9 +47,7 @@ class TcaColumnsProcessShowitem implements FormDataProviderInterface
             return $result;
         }
 
-        $showItemFieldString = !empty($result['overruleTypesArray'][$recordTypeValue]['showitem'])
-            ? $result['overruleTypesArray'][$recordTypeValue]['showitem']
-            : $result['processedTca']['types'][$recordTypeValue]['showitem'];
+        $showItemFieldString = $result['processedTca']['types'][$recordTypeValue]['showitem'];
         $showItemFieldArray = GeneralUtility::trimExplode(',', $showItemFieldString, true);
 
         foreach ($showItemFieldArray as $fieldConfigurationString) {
index 86c141f..78b2705 100644 (file)
@@ -208,9 +208,9 @@ class TcaInline extends AbstractDatabaseRecordProvider implements FormDataProvid
     {
         $parentConfig = $result['processedTca']['columns'][$parentFieldName]['config'];
         $childTableName = $parentConfig['foreign_table'];
-        $overruleTypesArray = [];
+        $inlineOverruleTypesArray = [];
         if (isset($parentConfig['foreign_types'])) {
-            $overruleTypesArray = $parentConfig['foreign_types'];
+            $inlineOverruleTypesArray = $parentConfig['foreign_types'];
         }
         /** @var TcaDatabaseRecord $formDataGroup */
         $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
@@ -221,7 +221,7 @@ class TcaInline extends AbstractDatabaseRecordProvider implements FormDataProvid
             'tableName' => $childTableName,
             'vanillaUid' => (int)$childUid,
             'inlineFirstPid' => $result['inlineFirstPid'],
-            'overruleTypesArray' => $overruleTypesArray,
+            'inlineOverruleTypesArray' => $inlineOverruleTypesArray,
         ];
         // For foreign_selector with useCombination $mainChild is the mm record
         // and $combinationChild is the child-child. For "normal" relations, $mainChild
index 106f584..c674c8e 100644 (file)
@@ -44,11 +44,6 @@ class TcaTypesShowitem implements FormDataProviderInterface
 
         $recordTypeValue = $result['recordTypeValue'];
 
-        // Inline may override the type value - setting is given down from InlineRecordContainer if so - used primarily for FAL
-        if (!empty($result['overruleTypesArray'][$recordTypeValue]['showitem'])) {
-            $result['processedTca']['types'][$recordTypeValue]['showitem'] = $result['overruleTypesArray'][$recordTypeValue]['showitem'];
-        }
-
         // Handle subtype_value_field, subtypes_addlist, subtypes_excludelist
         if (!empty($result['processedTca']['types'][$recordTypeValue]['subtype_value_field'])) {
             $subtypeFieldName = $result['processedTca']['types'][$recordTypeValue]['subtype_value_field'];
diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/InlineOverruleTypesArrayTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/InlineOverruleTypesArrayTest.php
new file mode 100644 (file)
index 0000000..5d05ac0
--- /dev/null
@@ -0,0 +1,97 @@
+<?php
+namespace typo3\sysext\backend\Tests\Unit\Form\FormDataProvider;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+use TYPO3\CMS\Backend\Form\FormDataProvider\InlineOverruleTypesArray;
+use TYPO3\CMS\Core\Tests\UnitTestCase;
+
+/**
+ * InlineOverruleTypesArray Test file
+ */
+class InlineOverruleTypesArrayTest extends UnitTestCase
+{
+
+    /**
+     * @var InlineOverruleTypesArray
+     */
+    protected $subject;
+
+    protected function setUp()
+    {
+        $this->subject = new InlineOverruleTypesArray();
+    }
+
+    /**
+     * @test
+     */
+    public function addDataOverrulesShowitemsByGivenInlineOverruleTypes()
+    {
+        $input = [
+            'inlineOverruleTypesArray' => [
+                'aType' => [
+                    'showitem' => 'keepMe'
+                ]
+            ],
+            'processedTca' => [
+                'types' => [
+                    'aType' => [
+                        'showitem' => 'keepMe, aField',
+                    ],
+                    'bType' => [
+                        'showitem' => 'keepMe, aField',
+                    ],
+                ],
+            ]
+        ];
+
+        $expected = $input;
+        $expected['processedTca']['types']['aType']['showitem'] = 'keepMe';
+
+        $this->assertSame($expected, $this->subject->addData($input));
+    }
+
+    /**
+     * @test
+     */
+    public function addDataAddsTypeShowitemsByGivenInlineOverruleTypes()
+    {
+        $input = [
+            'inlineOverruleTypesArray' => [
+                'aType' => [
+                    'showitem' => 'keepMe'
+                ],
+                'cType' => [
+                    'showitem' => 'keepMe'
+                ],
+            ],
+            'processedTca' => [
+                'types' => [
+                    'aType' => [
+                        'showitem' => 'keepMe, aField',
+                    ],
+                    'bType' => [
+                        'showitem' => 'keepMe, aField',
+                    ],
+                ],
+            ]
+        ];
+
+        $expected = $input;
+        $expected['processedTca']['types']['aType']['showitem'] = 'keepMe';
+        $expected['processedTca']['types']['cType']['showitem'] = 'keepMe';
+
+        $this->assertSame($expected, $this->subject->addData($input));
+    }
+
+}
index bf54e3f..b10ff3f 100644 (file)
@@ -93,47 +93,6 @@ class TcaColumnsProcessShowitemTest extends UnitTestCase
     /**
      * @test
      */
-    public function addDataRegistersColumnsFieldReferencedInOverruledShowitems()
-    {
-        $input = [
-            'columnsToProcess' => [],
-            'databaseRow' => [],
-            'recordTypeValue' => 'aType',
-            'overruleTypesArray' => [
-                'aType' => [
-                    'showitem' => 'keepMe'
-                ]
-            ],
-            'processedTca' => [
-                'types' => [
-                    'aType' => [
-                        'showitem' => 'aField'
-                    ],
-                ],
-                'columns' => [
-                    'keepMe' => [
-                        'config' => [
-                            'type' => 'input',
-                        ]
-                    ],
-                    'aField' => [
-                        'config' => [
-                            'type' => 'input',
-                        ]
-                    ]
-                ]
-            ]
-        ];
-
-        $expected = $input;
-        $expected['columnsToProcess'] = ['keepMe'];
-
-        $this->assertSame($expected, $this->subject->addData($input));
-    }
-
-    /**
-     * @test
-     */
     public function addDataKeepsColumnsFieldReferencedInPalette()
     {
         $input = [
index 91c655e..a4f4cbe 100644 (file)
@@ -424,6 +424,11 @@ return array(
                             \TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsOverrides::class
                         ),
                     ),
+                    \TYPO3\CMS\Backend\Form\FormDataProvider\InlineOverruleTypesArray::class => array(
+                        'depends' => array(
+                            \TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsOverrides::class,
+                        ),
+                    ),
                     \TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsProcessShowitem::class => array(
                         'depends' => array(
                             \TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsOverrides::class
@@ -431,10 +436,10 @@ return array(
                     ),
                     \TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsRemoveUnused::class => array(
                         'depends' => array(
-                            \TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsOverrides::class,
                             \TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsProcessCommon::class,
                             \TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsProcessRecordTitle::class,
                             \TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsProcessPlaceholders::class,
+                            \TYPO3\CMS\Backend\Form\FormDataProvider\InlineOverruleTypesArray::class,
                             \TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsProcessShowitem::class,
                         ),
                     ),