[BUGFIX] Field is not added to TCA if part of fieldname exists 80/48780/2
authorWouter Wolters <typo3@wouterwolters.nl>
Thu, 23 Jun 2016 21:46:20 +0000 (23:46 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Sat, 2 Jul 2016 21:37:29 +0000 (23:37 +0200)
Explode current showitem and check if new field is already
available instead of using a wrong strpos check.

Resolves: #73490
Releases: master,7.6,6.2
Change-Id: If0269a1ee783ec8468ac3f7df915b671f17312ff
Reviewed-on: https://review.typo3.org/48780
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php

index 67c63b7..109215c 100644 (file)
@@ -304,7 +304,12 @@ class ExtensionManagementUtility
                 continue;
             }
             // skip if fields were already added
-            if (!isset($typeDetails['showitem']) || strpos($typeDetails['showitem'], $newFieldsString) !== false) {
+            if (!isset($typeDetails['showitem'])) {
+                continue;
+            }
+
+            $fieldArray = GeneralUtility::trimExplode(',', $typeDetails['showitem'], true);
+            if (in_array($newFieldsString, $fieldArray, true)) {
                 continue;
             }
 
index 6f2c4cb..15b8290 100644 (file)
@@ -403,6 +403,18 @@ class ExtensionManagementUtilityTest extends UnitTestCase
     }
 
     /**
+     * @test
+     */
+    public function canAddFieldWithPartOfAlreadyExistingFieldname()
+    {
+        $table = $this->getUniqueId('tx_coretest_table');
+        $GLOBALS['TCA'] = $this->generateTCAForTable($table);
+        ExtensionManagementUtility::addToAllTCAtypes($table, 'field', 'typeA', 'after:fieldD1');
+
+        $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1, field', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
+    }
+
+    /**
      * Test wheter replacing other TCA fields works as promissed
      *
      * @test