[BUGFIX] TCA: subtypes_addlist not processed 49/9549/5
authorBenjamin Mack <benni@typo3.org>
Sat, 6 Apr 2013 09:54:32 +0000 (11:54 +0200)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Sat, 17 Aug 2013 17:59:26 +0000 (19:59 +0200)
TCA: subtypes_addlist is not processed
if the subtype_value_field is in a palette

Fixes: #30636
Releases: 6.2, 6.1, 6.0, 4.7, 4.5
Change-Id: I6bcaaf36c330962c1d7d9fdd4a73ae502e9710dc
Reviewed-on: https://review.typo3.org/9549
Reviewed-by: Wouter Wolters
Tested-by: Lucas Bremgartner
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
typo3/sysext/backend/Classes/Form/FormEngine.php

index 055efc7..f3e7b3b 100644 (file)
@@ -738,7 +738,7 @@ class FormEngine {
                                        }
                                        // Get excluded fields, added fiels and put it together:
                                        $excludeElements = ($this->excludeElements = $this->getExcludeElements($table, $row, $typeNum));
-                                       $fields = $this->mergeFieldsWithAddedFields($fields, $this->getFieldsToAdd($table, $row, $typeNum));
+                                       $fields = $this->mergeFieldsWithAddedFields($fields, $this->getFieldsToAdd($table, $row, $typeNum), $table);
                                        // If TCEforms will render a tab menu in the next step, push the name to the tab stack:
                                        $tabIdentString = '';
                                        $tabIdentStringMD5 = '';
@@ -3332,18 +3332,39 @@ function ' . $evalData . '(value) {
        /**
         * Merges the current [types][showitem] array with the array of fields to add for the current subtype field of the "type" value.
         *
-        * @param array A [types][showitem] list of fields, exploded by ",
-        * @param array The output from getFieldsToAdd()
+        * @param array $fields A [types][showitem] list of fields, exploded by ",
+        * @param array $fieldsToAdd The output from getFieldsToAdd()
+        * @param string $table The table name, if we want to consider it's palettes when positioning the new elements
         * @return array Return the modified $fields array.
         * @see getMainFields(),getFieldsToAdd()
         * @todo Define visibility
         */
-       public function mergeFieldsWithAddedFields($fields, $fieldsToAdd) {
+       public function mergeFieldsWithAddedFields($fields, $fieldsToAdd, $table = '') {
                if (count($fieldsToAdd[0])) {
                        $c = 0;
+                       $found = FALSE;
                        foreach ($fields as $fieldInfo) {
-                               $parts = explode(';', $fieldInfo);
-                               if (!strcmp(trim($parts[0]), $fieldsToAdd[1])) {
+                               list($fieldName, $label, $paletteName) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(';', $fieldInfo);
+                               if ($fieldName === $fieldsToAdd[1]) {
+                                       $found = TRUE;
+                               } elseif ($fieldName === '--palette--' && $paletteName && $table !== '') {
+                                       // Look inside the palette
+                                       if (is_array($GLOBALS['TCA'][$table]['palettes'][$paletteName])) {
+                                               $itemList = $GLOBALS['TCA'][$table]['palettes'][$paletteName]['showitem'];
+                                               if ($itemList) {
+                                                       $paletteFields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $itemList, TRUE);
+                                                       foreach ($paletteFields as $info) {
+                                                               $fieldParts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(';', $info);
+                                                               $theField = $fieldParts[0];
+                                                               if ($theField === $fieldsToAdd[1]) {
+                                                                       $found = TRUE;
+                                                                       break 1;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                               if ($found) {
                                        array_splice($fields, $c + 1, 0, $fieldsToAdd[0]);
                                        break;
                                }