[BUGFIX] addToAllTCAtypes() must replace fields correctly 10/39910/3
authorMarkus Klein <markus.klein@typo3.org>
Wed, 3 Jun 2015 08:40:51 +0000 (10:40 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 3 Jun 2015 15:12:38 +0000 (17:12 +0200)
The changes made in #57824 cause the replace functionality to fail.

Resolves: #67259
Releases: master, 6.2
Change-Id: If0d5773f2905bdae50ab7aa607c01422d18e7f81
Reviewed-on: http://review.typo3.org/39910
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: rengaw83 <rengaw83@gmx.de>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php

index dd1ea00..22aa8b4 100644 (file)
@@ -274,7 +274,7 @@ class ExtensionManagementUtility {
         * @param string $table Table name
         * @param string $newFieldsString Field list to add.
         * @param string $typeList List of specific types to add the field list to. (If empty, all type entries are affected)
-        * @param string $position Insert fields before (default) or after one
+        * @param string $position Insert fields before (default) or after one, or replace a field
         * @return void
         */
        static public function addToAllTCAtypes($table, $newFieldsString, $typeList = '', $position = '') {
@@ -297,7 +297,6 @@ class ExtensionManagementUtility {
 
                        $fieldExists = FALSE;
                        $newPosition = '';
-                       $paletteNames = array();
                        if (is_array($GLOBALS['TCA'][$table]['palettes'])) {
                                // Get the palette names used in current showitem
                                $paletteCount = preg_match_all('/(?:^|,)                    # Line start or a comma
@@ -307,7 +306,7 @@ class ExtensionManagementUtility {
                                        )/x', $typeDetails['showitem'], $paletteMatches);
                                if ($paletteCount > 0) {
                                        $paletteNames = array_filter(array_merge($paletteMatches[1], $paletteMatches[2]));
-                                       if (count($paletteNames)) {
+                                       if (!empty($paletteNames)) {
                                                foreach ($paletteNames as $paletteName) {
                                                        $palette = $GLOBALS['TCA'][$table]['palettes'][$paletteName];
                                                        switch ($positionIdentifier) {
@@ -592,7 +591,11 @@ class ExtensionManagementUtility {
        static protected function executePositionedStringInsertion($list, $insertionList, $insertionPosition = '') {
                $list = $newList = trim($list, ", \t\n\r\0\x0B");
 
-               $insertionList = self::removeDuplicatesForInsertion($insertionList, $list);
+               list($location, $positionName) = GeneralUtility::trimExplode(':', $insertionPosition);
+
+               if ($location !== 'replace') {
+                       $insertionList = self::removeDuplicatesForInsertion($insertionList, $list);
+               }
 
                if ($insertionList === '') {
                        return $list;
@@ -604,7 +607,6 @@ class ExtensionManagementUtility {
                        return $list . ', ' . $insertionList;
                }
 
-               list($location, $positionName) = GeneralUtility::trimExplode(':', $insertionPosition);
                // The $insertPosition may be a palette: after:--palette--;;title
                // In the $list the palette may contain a LLL string in between the ;;
                // Adjust the regex to match that
index 71f3c0a..01a39de 100644 (file)
@@ -375,12 +375,29 @@ class ExtensionManagementUtilityTest extends UnitTestCase {
                $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
                // unchanged because the palette is not used
                $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
-               // unchanged because the palette is not used
                $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
+               // changed
                $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
                $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
        }
 
+       /**
+        * @test
+        */
+       public function addToAllTCAtypesReplacesExistingOnes() {
+               $table = $this->getUniqueId('tx_coretest_table');
+               $GLOBALS['TCA'] = $this->generateTCAForTable($table);
+               $typesBefore = $GLOBALS['TCA'][$table]['types'];
+               ExtensionManagementUtility::addToAllTCAtypes($table, 'fieldX;;foo;;', '', 'replace:fieldX');
+               $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
+               // unchanged because the palette is not used
+               $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
+               $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
+               // changed
+               $this->assertEquals('fieldX;;foo;;, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
+               $this->assertEquals('fieldX;;foo;;, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
+       }
+
        ///////////////////////////////////////////////////
        // Tests concerning addFieldsToAllPalettesOfField
        ///////////////////////////////////////////////////