[BUGFIX] Select icon added via pageTsConfig not shown 66/51766/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Mon, 20 Feb 2017 09:30:29 +0000 (10:30 +0100)
committerAndreas Fernandez <typo3@scripting-base.de>
Tue, 21 Feb 2017 19:16:23 +0000 (20:16 +0100)
Fix for issue #78628 fixed "addItems" for TCA trees, but broke them
for select drop downs. Juggle icon providing around a bit to fix.

Change-Id: I3a1077992a7db0d72bc2d7d0247292763cc25958
Resolves: #78747
Related: #78628
Releases: master
Reviewed-on: https://review.typo3.org/51766
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php
typo3/sysext/backend/Classes/Form/FormDataProvider/TcaSelectTreeItems.php

index 14f4ed0..302429c 100644 (file)
@@ -120,8 +120,6 @@ abstract class AbstractItemProvider
     {
         $table = $result['tableName'];
         $iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
-        $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
-
         if (!empty($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['addItems.'])
             && is_array($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['addItems.'])
         ) {
@@ -132,7 +130,7 @@ abstract class AbstractItemProvider
                     continue;
                 }
                 // Check if value "34 = mylabel" also has a "34.icon = myImage.png"
-                $icon = null;
+                $iconIdentifier = null;
                 if (isset($addItemsArray[$value . '.'])
                     && is_array($addItemsArray[$value . '.'])
                     && !empty($addItemsArray[$value . '.']['icon'])
@@ -155,9 +153,8 @@ abstract class AbstractItemProvider
                             );
                         }
                     }
-                    $icon = $iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->getMarkup('inline');
                 }
-                $items[] = [$label, $value, $icon];
+                $items[] = [$label, $value, $iconIdentifier];
             }
         }
         return $items;
index 5c05d6f..3ec43b6 100644 (file)
@@ -15,6 +15,8 @@ namespace TYPO3\CMS\Backend\Form\FormDataProvider;
  */
 
 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
+use TYPO3\CMS\Core\Imaging\Icon;
+use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Tree\TableConfiguration\ExtJsArrayTreeRenderer;
 use TYPO3\CMS\Core\Tree\TableConfiguration\TableConfigurationTree;
 use TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory;
@@ -91,15 +93,26 @@ class TcaSelectTreeItems extends AbstractItemProvider implements FormDataProvide
                 // "static" and "dynamic" is separated since the tree code only copes with "real" existing foreign nodes,
                 // so this "static" stuff allows defining tree items that don't really exist in the tree.
                 $itemsFromTca = $this->sanitizeItemArray($fieldConfig['config']['items'], $table, $fieldName);
+
                 // List of additional items defined by page ts config "addItems"
                 $itemsFromPageTsConfig = $this->addItemsFromPageTsConfig($result, $fieldName, []);
-                if (!empty($itemsFromTca) || !empty($itemsFromPageTsConfig)) {
+                // Resolve pageTsConfig item icons to markup
+                $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
+                $finalPageTsConfigItems = [];
+                foreach ($itemsFromPageTsConfig as $item) {
+                    if ($item[2] !== null) {
+                        $item[2] = $iconFactory->getIcon($item[2], Icon::SIZE_SMALL)->getMarkup('inline');
+                    }
+                    $finalPageTsConfigItems[] = $item;
+                }
+
+                if (!empty($itemsFromTca) || !empty($finalPageTsConfigItems)) {
                     // First apply "keepItems" to $itemsFromTca, this will restrict the tca item list to only
                     // those items that are defined in page ts "keepItems" if given
                     $itemsFromTca = $this->removeItemsByKeepItemsPageTsConfig($result, $fieldName, $itemsFromTca);
                     // Then, merge the items from page ts "addItems" into item list, since "addItems" should
                     // add additional items even if they are not in the "keepItems" list
-                    $staticItems = array_merge($itemsFromTca, $itemsFromPageTsConfig);
+                    $staticItems = array_merge($itemsFromTca, $finalPageTsConfigItems);
                     // Now apply page ts config "removeItems", so this is *after* addItems, so "removeItems" could
                     // possibly remove items again that were added via "addItems"
                     $staticItems = $this->removeItemsByRemoveItemsPageTsConfig($result, $fieldName, $staticItems);