[BUGFIX] Add TCA migration for columnsOverrides as well 89/52189/6
authorHelmut Hummel <typo3@helhum.io>
Mon, 27 Mar 2017 16:27:26 +0000 (18:27 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Wed, 29 Mar 2017 19:18:29 +0000 (21:18 +0200)
When migrating old TCA configuration to overrideChildTca,
we must respect columnsOverrides and do the migration there as well.

Also fix the examples for overriding cropVariants, which missed some
nesting levels

Resolves: #80493
Releases: master
Change-Id: If38f445e545b6f93eead5f30cfc16e787343b8c6
Reviewed-on: https://review.typo3.org/52189
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Classes/Migrations/TcaMigration.php
typo3/sysext/core/Documentation/Changelog/8.6/Feature-75880-ImplementMultipleCroppingVariantsInImageManipulationTool.rst
typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php

index b7b67b1..d4b289e 100644 (file)
@@ -2425,6 +2425,51 @@ class TcaMigration
     protected function migrateInlineOverrideChildTca(array $tca): array
     {
         foreach ($tca as $table => &$tableDefinition) {
+            if (isset($tableDefinition['types']) && is_array($tableDefinition['types'])) {
+                foreach ($tableDefinition['types'] as $typeName => &$typeConfig) {
+                    if (!isset($typeConfig['columnsOverrides']) || !is_array($typeConfig['columnsOverrides'])) {
+                        continue;
+                    }
+                    foreach ($typeConfig['columnsOverrides'] as $fieldName => &$fieldConfig) {
+                        if (isset($fieldConfig['config']['overrideChildTca'])
+                            || (isset($fieldConfig['config']['type']) && $fieldConfig['config']['type'] !== 'inline')
+                            || (!isset($fieldConfig['config']['type']) && $tca[$table]['columns'][$fieldName]['config']['type'] !== 'inline')
+                        ) {
+                            // The new config is either set intentionally for compatibility
+                            // or accidentally. In any case we keep the new config and skip the migration.
+                            continue;
+                        }
+                        if (isset($fieldConfig['config']['foreign_types']) && is_array($fieldConfig['config']['foreign_types'])) {
+                            $fieldConfig['config']['overrideChildTca']['types'] = $fieldConfig['config']['foreign_types'];
+                            unset($fieldConfig['config']['foreign_types']);
+                            $this->messages[] = 'The \'foreign_types\' property from TCA ' . $table . '[\'types\'][\'' . $typeName . '\'][\'columnOverrides\'][\'' . $fieldName . '\'][\'config\']  and has been migrated to ' . $table . '[\'types\'][\'' . $typeName . '\'][\'columnOverrides\'][\'' . $fieldName . '\'][\'config\'][\'overrideChildTca\'][\'types\']';
+                        }
+                        if (isset($fieldConfig['config']['foreign_selector_fieldTcaOverride']) && is_array($fieldConfig['config']['foreign_selector_fieldTcaOverride'])) {
+
+                            if (isset($fieldConfig['config']['foreign_selector']) && is_string($fieldConfig['config']['foreign_selector'])) {
+                                $foreignSelectorFieldName = $fieldConfig['config']['foreign_selector'];
+                            } elseif (isset($tca[$table]['columns'][$fieldName]['config']['foreign_selector']) && is_string($tca[$table]['columns'][$fieldName]['config']['foreign_selector'])) {
+                                $foreignSelectorFieldName = $tca[$table]['columns'][$fieldName]['config']['foreign_selector'];
+                            }
+
+                            if ($foreignSelectorFieldName) {
+                                $fieldConfig['config']['overrideChildTca']['columns'][$foreignSelectorFieldName] = $fieldConfig['config']['foreign_selector_fieldTcaOverride'];
+                                unset($fieldConfig['config']['foreign_selector_fieldTcaOverride']);
+                                $this->messages[] = 'The \'foreign_selector_fieldTcaOverride\' property from TCA ' . $table . '[\'types\'][\'' . $typeName . '\'][\'columnOverrides\'][\'' . $fieldName . '\'][\'config\']  and has been migrated to ' . $table . '[\'types\'][\'' . $typeName . '\'][\'columnOverrides\'][\'' . $fieldName . '\'][\'config\'][\'overrideChildTca\'][\'columns\'][\'' . $foreignSelectorFieldName . '\']';
+                            }
+                        }
+                        if (isset($fieldConfig['config']['foreign_record_defaults']) && is_array($fieldConfig['config']['foreign_record_defaults'])) {
+                            foreach ($fieldConfig['config']['foreign_record_defaults'] as $childFieldName => $defaultValue) {
+                                $fieldConfig['config']['overrideChildTca']['columns'][$childFieldName]['config']['default'] = $defaultValue;
+                                $this->messages[] = 'The \'foreign_record_defaults\' property from TCA ' . $table . '[\'types\'][\'' . $typeName . '\'][\'columnOverrides\'][\'' . $fieldName . '\'][\'config\'][\'' . $childFieldName . '\']  and has been migrated to ' . $table . '[\'types\'][\'' . $typeName . '\'][\'columnOverrides\'][\'' . $fieldName . '\'][\'config\'][\'overrideChildTca\'][\'columns\'][\'' . $childFieldName . '\'][\'config\'][\'default\']';
+                            }
+                            unset($fieldConfig['config']['foreign_record_defaults']);
+                        }
+                    }
+                    unset($fieldConfig);
+                }
+                unset($typeConfig);
+            }
             if (isset($tableDefinition['columns']) && is_array($tableDefinition['columns'])) {
                 foreach ($tableDefinition['columns'] as $fieldName => &$fieldConfig) {
                     if (isset($fieldConfig['config']['overrideChildTca'])
@@ -2437,32 +2482,23 @@ class TcaMigration
                     if (isset($fieldConfig['config']['foreign_types']) && is_array($fieldConfig['config']['foreign_types'])) {
                         $fieldConfig['config']['overrideChildTca']['types'] = $fieldConfig['config']['foreign_types'];
                         unset($fieldConfig['config']['foreign_types']);
-                        $this->messages[] = 'The \'foreign_types\' property from TCA ' . $table
-                            . '[\'columns\'][\'' . $fieldName . '\'][\'config\']  and has been migrated to '
-                            . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'overrideChildTca\'][\'types\']';
+                        $this->messages[] = 'The \'foreign_types\' property from TCA ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\']  and has been migrated to ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'overrideChildTca\'][\'types\']';
                     }
-                    if (isset($fieldConfig['config']['foreign_selector'], $fieldConfig['config']['foreign_selector_fieldTcaOverride'])
-                        && is_string($fieldConfig['config']['foreign_selector'])
-                        && is_array($fieldConfig['config']['foreign_selector_fieldTcaOverride'])
-                    ) {
+                    if (isset($fieldConfig['config']['foreign_selector'], $fieldConfig['config']['foreign_selector_fieldTcaOverride']) && is_string($fieldConfig['config']['foreign_selector']) && is_array($fieldConfig['config']['foreign_selector_fieldTcaOverride'])) {
                         $foreignSelectorFieldName = $fieldConfig['config']['foreign_selector'];
-                        $fieldConfig['config']['overrideChildTca']['columns'][$foreignSelectorFieldName]
-                            = $fieldConfig['config']['foreign_selector_fieldTcaOverride'];
+                        $fieldConfig['config']['overrideChildTca']['columns'][$foreignSelectorFieldName] = $fieldConfig['config']['foreign_selector_fieldTcaOverride'];
                         unset($fieldConfig['config']['foreign_selector_fieldTcaOverride']);
-                        $this->messages[] = 'The \'foreign_selector_fieldTcaOverride\' property from TCA ' . $table
-                            . '[\'columns\'][\'' . $fieldName . '\'][\'config\']  and has been migrated to ' . $table
-                            . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'overrideChildTca\'][\'columns\'][\'' . $foreignSelectorFieldName . '\']';
+                        $this->messages[] = 'The \'foreign_selector_fieldTcaOverride\' property from TCA ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\']  and has been migrated to ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'overrideChildTca\'][\'columns\'][\'' . $foreignSelectorFieldName . '\']';
                     }
                     if (isset($fieldConfig['config']['foreign_record_defaults']) && is_array($fieldConfig['config']['foreign_record_defaults'])) {
                         foreach ($fieldConfig['config']['foreign_record_defaults'] as $childFieldName => $defaultValue) {
                             $fieldConfig['config']['overrideChildTca']['columns'][$childFieldName]['config']['default'] = $defaultValue;
-                            $this->messages[] = 'The \'foreign_record_defaults\' property from TCA ' . $table
-                                . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'' . $childFieldName . '\']  and has been migrated to ' . $table
-                                . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'overrideChildTca\'][\'columns\'][\'' . $childFieldName . '\'][\'config\'][\'default\']';
+                            $this->messages[] = 'The \'foreign_record_defaults\' property from TCA ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'' . $childFieldName . '\']  and has been migrated to ' . $table . '[\'columns\'][\'' . $fieldName . '\'][\'config\'][\'overrideChildTca\'][\'columns\'][\'' . $childFieldName . '\'][\'config\'][\'default\']';
                         }
                         unset($fieldConfig['config']['foreign_record_defaults']);
                     }
                 }
+                unset($fieldConfig);
             }
         }
 
index f972e27..cc605e8 100644 (file)
@@ -141,13 +141,17 @@ cropping configuration for tt_content images, then you can add the following to
         'overrideChildTca' => [
             'columns' => [
                 'crop' => [
-                    'mobile' => [
-                        'title' => 'LLL:EXT:ext_key/Resources/Private/Language/locallang.xlf:imageManipulation.mobile',
-                        'cropArea' => [
-                            'x' => 0.1,
-                            'y' => 0.1,
-                            'width' => 0.8,
-                            'height' => 0.8,
+                    'config' => [
+                        'cropVariants' => [
+                            'mobile' => [
+                                'title' => 'LLL:EXT:ext_key/Resources/Private/Language/locallang.xlf:imageManipulation.mobile',
+                                'cropArea' => [
+                                    'x' => 0.1,
+                                    'y' => 0.1,
+                                    'width' => 0.8,
+                                    'height' => 0.8,
+                                ],
+                            ],
                         ],
                     ],
                 ],
@@ -161,8 +165,8 @@ as this is the default field name for image manipulation in `sys_file_reference`
 It is also possible to set the cropping configuration only for a specific tt_content element type by using the
 `columnOverrides` feature:
 
-    $GLOBALS['TCA']['tt_content']['types']['textmedia']['columnsOverrides']['assets']['config']['overrideChildTca']['columns'] = [
-        'crop' => [
+    $GLOBALS['TCA']['tt_content']['types']['textmedia']['columnsOverrides']['assets']['config']['overrideChildTca']['columns']['crop']['config'] = [
+        'cropVariants' => [
            'default' => [
                'disabled' => true,
            ],
index 6e11ad0..936caf1 100644 (file)
@@ -5153,7 +5153,7 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     public function migrateSuggestWizardDataProvider()
     {
         return [
-            'no suggest wizard in main field but configured in columnOverrides' => [
+            'no suggest wizard in main field but configured in columnsOverrides' => [
                 [
                     'aTable' => [
                         'columns' => [
@@ -5208,7 +5208,7 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
                     ],
                 ],
             ],
-            'no suggest wizard in main field but configured in columnOverrides with options' => [
+            'no suggest wizard in main field but configured in columnsOverrides with options' => [
                 [
                     'aTable' => [
                         'columns' => [
@@ -6295,4 +6295,212 @@ class TcaMigrationTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $subject = new TcaMigration();
         $this->assertEquals($expected, $subject->migrate($input));
     }
+
+    /**
+     * @test
+     */
+    public function migrateAllOverridesFromColumnOverride()
+    {
+        $input = [
+            'aTable' => [
+                'types' => [
+                    'textmedia' => [
+                        'columnsOverrides' => [
+                            'assets' => [
+                                'config' => [
+                                    'type' => 'inline',
+                                    'foreign_selector' => 'uid_local',
+                                    'foreign_types' => [
+                                        '0' => [
+                                            'showitem' => 'bar'
+                                        ],
+                                    ],
+                                    'foreign_selector_fieldTcaOverride' => [
+                                        'label' => 'aDifferentLabel',
+                                        'config' => [
+                                            'aGivenSetting' => 'overrideValue',
+                                            'aNewSetting' => 'anotherNewValue',
+                                            'appearance' => [
+                                                'elementBrowserType' => 'file',
+                                                'elementBrowserAllowed' => 'jpg,png'
+                                            ],
+                                        ],
+                                    ],
+                                    'foreign_record_defaults' => [
+                                        'aField' => 'overriddenValue',
+                                        'bField' => 'overriddenValue',
+                                    ],
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $expected = [
+            'aTable' => [
+                'types' => [
+                    'textmedia' => [
+                        'columnsOverrides' => [
+                            'assets' => [
+                                'config' => [
+                                    'type' => 'inline',
+                                    'foreign_selector' => 'uid_local',
+                                    'overrideChildTca' => [
+                                        'types' => [
+                                            '0' => [
+                                                'showitem' => 'bar'
+                                            ],
+                                        ],
+                                        'columns' => [
+                                            'uid_local' => [
+                                                'label' => 'aDifferentLabel',
+                                                'config' => [
+                                                    'aGivenSetting' => 'overrideValue',
+                                                    'aNewSetting' => 'anotherNewValue',
+                                                    'appearance' => [
+                                                        'elementBrowserType' => 'file',
+                                                        'elementBrowserAllowed' => 'jpg,png'
+                                                    ],
+                                                ],
+                                            ],
+                                            'aField' => [
+                                                'config' => [
+                                                    'default' => 'overriddenValue'
+                                                ],
+                                            ],
+                                            'bField' => [
+                                                'config' => [
+                                                    'default' => 'overriddenValue'
+                                                ],
+                                            ],
+                                        ],
+                                    ],
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $subject = new TcaMigration();
+        $this->assertEquals($expected, $subject->migrate($input));
+    }
+
+    /**
+     * @test
+     */
+    public function migratePartlyOverridesFromColumnOverride()
+    {
+        $input = [
+            'aTable' => [
+                'columns' => [
+                    'assets' => [
+                        'config' => [
+                            'type' => 'inline',
+                            'foreign_selector' => 'uid_local',
+                            'overrideChildTca' => [
+                                'types' => [
+                                    '0' => [
+                                        'showitem' => 'foo'
+                                    ],
+                                ],
+                                'columns' => [
+                                    'uid_local' => [
+                                        'label' => 'Label',
+                                        'config' => [
+                                            'appearance' => [
+                                                'elementBrowserType' => 'file',
+                                                'elementBrowserAllowed' => 'jpg,png'
+                                            ],
+                                        ],
+                                    ],
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+                'types' => [
+                    'textmedia' => [
+                        'columnsOverrides' => [
+                            'assets' => [
+                                'config' => [
+                                    'foreign_types' => [
+                                        '0' => [
+                                            'showitem' => 'bar'
+                                        ],
+                                    ],
+                                    'foreign_selector_fieldTcaOverride' => [
+                                        'config' => [
+                                            'appearance' => [
+                                                'elementBrowserAllowed' => 'jpg,png'
+                                            ],
+                                        ],
+                                    ],
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $expected = [
+            'aTable' => [
+                'columns' => [
+                    'assets' => [
+                        'config' => [
+                            'type' => 'inline',
+                            'foreign_selector' => 'uid_local',
+                            'overrideChildTca' => [
+                                'types' => [
+                                    '0' => [
+                                        'showitem' => 'foo'
+                                    ],
+                                ],
+                                'columns' => [
+                                    'uid_local' => [
+                                        'label' => 'Label',
+                                        'config' => [
+                                            'appearance' => [
+                                                'elementBrowserType' => 'file',
+                                                'elementBrowserAllowed' => 'jpg,png'
+                                            ],
+                                        ],
+                                    ],
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+                'types' => [
+                    'textmedia' => [
+                        'columnsOverrides' => [
+                            'assets' => [
+                                'config' => [
+                                    'overrideChildTca' => [
+                                        'types' => [
+                                            '0' => [
+                                                'showitem' => 'bar'
+                                            ],
+                                        ],
+                                        'columns' => [
+                                            'uid_local' => [
+                                                'config' => [
+                                                    'appearance' => [
+                                                        'elementBrowserAllowed' => 'jpg,png'
+                                                    ],
+                                                ],
+                                            ],
+                                        ],
+                                    ],
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $subject = new TcaMigration();
+        $this->assertEquals($expected, $subject->migrate($input));
+    }
 }