[BUGFIX] Create only minimum TCA when adding new palettes 42/40042/2
authorMarkus Klein <markus.klein@typo3.org>
Sat, 6 Jun 2015 12:20:32 +0000 (14:20 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Tue, 9 Jun 2015 14:11:41 +0000 (16:11 +0200)
When adding a new palette to TCA the types::showitem part is modified.
This patch ensures that no empty values are set to the field definitions
as this would trigger the TCA Migrator.

Resolves: #67327
Releases: master
Change-Id: I30cb6a7d6f325705528d1f3c2961e2620068f057
Reviewed-on: http://review.typo3.org/40042
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Frederic Gaus <frederic.gaus@flagbit.de>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php

index ebd3b07..bf2641b 100644 (file)
@@ -695,14 +695,12 @@ class ExtensionManagementUtility {
                        if (!isset($items[$key])) {
                                $items[$key] = array(
                                        'rawData' => $itemPart,
-                                       'details' => array(
-                                               'field' => $itemDetails[0],
-                                               'label' => $itemDetails[1],
-                                               'palette' => $itemDetails[2],
-                                               'special' => $itemDetails[3],
-                                               'styles' => $itemDetails[4]
-                                       )
+                                       'details' => array()
                                );
+                               $details = array(0 => 'field', 1 => 'label', 2 => 'palette', 3 => 'special', 4 => 'styles');
+                               foreach ($details as $id => $property) {
+                                       $items[$key]['details'][$property] = isset($itemDetails[$id]) ? $itemDetails[$id] : '';
+                               }
                        }
                }
                return $items;
@@ -726,7 +724,19 @@ class ExtensionManagementUtility {
                        if ($useRawData) {
                                $itemParts[] = $itemDetails['rawData'];
                        } else {
-                               $itemParts[] = count($itemDetails['details']) > 1 ? implode(';', $itemDetails['details']) : $item;
+                               if (count($itemDetails['details']) > 1) {
+                                       $details = array('styles', 'special', 'palette', 'label', 'field');
+                                       $elements = array();
+                                       $addEmpty = FALSE;
+                                       foreach ($details as $property) {
+                                               if ($itemDetails['details'][$property] !== '' || $addEmpty) {
+                                                       $addEmpty = TRUE;
+                                                       array_unshift($elements, $itemDetails['details'][$property]);
+                                               }
+                                       }
+                                       $item = implode(';', $elements);
+                               }
+                               $itemParts[] = $item;
                        }
                }
                return implode(', ', $itemParts);
index 01a39de..e85541a 100644 (file)
@@ -543,6 +543,8 @@ class ExtensionManagementUtilityTest extends UnitTestCase {
                $table = $this->getUniqueId('tx_coretest_table');
                $GLOBALS['TCA'] = $this->generateTCAForTable($table);
                ExtensionManagementUtility::addFieldsToAllPalettesOfField($table, 'fieldA', 'newA, newA, newB, fieldX');
+               // is palette reference added
+               $this->assertSame('fieldA;;generatedFor-fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
                $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
                $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
                $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);