[BUGFIX] fix t3lib_extMgm::addToAllTCAtypes(..... , 'replace:xxx')
authorTolleiv Nietsch <info@tolleiv.de>
Tue, 1 Mar 2011 09:22:33 +0000 (10:22 +0100)
committerStefan Galinski <stefan.galinski@gmail.com>
Tue, 1 Mar 2011 16:14:45 +0000 (17:14 +0100)
t3lib_extMgm::addToAllTCAtypes(..... , 'replace:xxx')
breaks when palette used in many types

Change-Id: I93e6e3a8e28ab4c9e15d12721e55b43882d63d04
Resolves: #M17777
Reviewed-on: http://review.typo3.org/948
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
Reviewed-by: Stefan Galinski <stefan.galinski@gmail.com>
t3lib/class.t3lib_extmgm.php
tests/t3lib/t3lib_extmgmTest.php

index 0b47a4d..398a618 100644 (file)
@@ -303,7 +303,7 @@ final class t3lib_extMgm {
        public static function addToAllTCAtypes($table, $str, $specificTypesList = '', $position = '') {
                t3lib_div::loadTCA($table);
                $str = trim($str);
-
+               $palettesChanged = array();
                if ($str && is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['types'])) {
                        foreach ($GLOBALS['TCA'][$table]['types'] as $type => &$typeDetails) {
                                if ($specificTypesList === '' || t3lib_div::inList($specificTypesList, $type)) {
@@ -315,6 +315,10 @@ final class t3lib_extMgm {
                                                                if (preg_match('/\b' . $palette . '\b/', $typeDetails['showitem']) > 0
                                                                                && preg_match('/\b' . $positionArray[1] . '\b/', $paletteDetails['showitem']) > 0) {
                                                                        self::addFieldsToPalette($table, $palette, $str, $position);
+                                                                               // save that palette in case other types use it
+                                                                       $palettesChanged[] = $palette;
+                                                                       $fieldExists = TRUE;
+                                                               } elseif (in_array($palette, $palettesChanged)) {
                                                                        $fieldExists = TRUE;
                                                                }
                                                        }
index fb162cf..1423663 100644 (file)
@@ -254,6 +254,44 @@ class t3lib_extmgmTest extends tx_phpunit_testcase {
                );
        }
 
+       /**
+        * Test wheter replacing other TCA fields works as promissed
+        * @test
+        * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
+        */
+       public function canAddFieldsToTCATypeAndReplaceExistingOnes() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'] = $this->generateTCAForTable($table);
+
+               $typesBefore = $GLOBALS['TCA'][$table]['types'];
+
+               t3lib_extMgm::addToAllTCAtypes($table, 'fieldZ', '', '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, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
+               );
+                       // unchanged because the palette is not used
+               $this->assertEquals(
+                       'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
+               );
+
+               $this->assertEquals(
+                       'fieldZ, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
+               );
+
+               $this->assertEquals(
+                       'fieldZ, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
+               );
+       }
+
+
 
        ///////////////////////////////////////////////////
        // Tests concerning addFieldsToAllPalettesOfField