[BUGFIX] Add icon rendering for custom permissions options 50/50450/2
authorBenjamin Serfhos <serfhos@gmail.com>
Wed, 13 Jul 2016 21:06:14 +0000 (23:06 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Mon, 31 Oct 2016 13:25:07 +0000 (14:25 +0100)
The icon rendering of custom page options was lost during
refactoring of the ItemProviders.

Resolves: #77075
Releases: master, 7.6
Change-Id: Iae6415525d94fc56c48332de9e5bc3980344fbc2
Reviewed-on: https://review.typo3.org/50450
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaSelectItemsTest.php
typo3/sysext/core/Classes/Imaging/IconRegistry.php

index e35baba..d6fa26a 100644 (file)
@@ -20,6 +20,7 @@ use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Database\RelationHandler;
 use TYPO3\CMS\Core\Imaging\IconFactory;
+use TYPO3\CMS\Core\Imaging\IconRegistry;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
 use TYPO3\CMS\Core\Messaging\FlashMessageService;
@@ -156,6 +157,7 @@ abstract class AbstractItemProvider
         }
 
         $languageService = $this->getLanguageService();
+        $iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
         $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
 
         $special = $result['processedTca']['columns'][$fieldName]['config']['special'];
@@ -289,6 +291,28 @@ abstract class AbstractItemProvider
                             foreach ($coValue['items'] as $itemKey => $itemCfg) {
                                 $icon = 'empty-empty';
                                 $helpText = [];
+                                if (!empty($itemCfg[1])) {
+                                    if ($iconRegistry->isRegistered($itemCfg[1])) {
+                                        // Use icon identifier when registered
+                                        $icon = $itemCfg[1];
+                                    } else {
+                                        // @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
+                                        GeneralUtility::deprecationLog(
+                                            'Using "EXT:path/to/icon" is deprecated since TYPO3 CMS 7 and removed since'
+                                            . ' version 8. Please register an icon in ext_tables.php with'
+                                            . ' $iconRegistry->registerIcon() and use the icon identifier in customPermOptions.'
+                                        );
+                                        // Generate custom option icon and reuse same identifier
+                                        $icon = 'custom-option-' . md5($itemCfg[1]);
+                                        if ($iconRegistry->isRegistered($icon) === false) {
+                                            $iconRegistry->registerIcon(
+                                                $icon,
+                                                $iconRegistry->detectIconProvider($itemCfg[1]),
+                                                ['source' => $itemCfg[1]]
+                                            );
+                                        }
+                                    }
+                                }
                                 if (!empty($itemCfg[2])) {
                                     $helpText['description'] = $languageService->sL($itemCfg[2]);
                                 }
index 5408f4b..01c7689 100644 (file)
@@ -1007,6 +1007,11 @@ class TcaSelectItemsTest extends UnitTestCase
                     'anItemKey' => [
                         0 => 'anItemTitle',
                     ],
+                    'anotherKey' => [
+                        0 => 'anotherTitle',
+                        1 => 'status-status-permission-denied',
+                        2 => 'aDescription',
+                    ],
                 ],
             ]
         ];
@@ -1024,6 +1029,12 @@ class TcaSelectItemsTest extends UnitTestCase
                 2 => 'empty-empty',
                 3 => null,
             ],
+            2 => [
+                0 => 'anotherTitle',
+                1 => 'aKey:anotherKey',
+                2 => 'status-status-permission-denied',
+                3 => [ 'description' => 'aDescription' ],
+            ],
         ];
 
         $result = $this->subject->addData($input);
index 6248dfb..c38d519 100644 (file)
@@ -2932,4 +2932,19 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface
         }
         $this->flagsInitialized = true;
     }
+
+    /**
+     * Detect the IconProvider of an icon
+     *
+     * @param string $iconReference
+     * @return string
+     */
+    public function detectIconProvider($iconReference)
+    {
+        if (StringUtility::endsWith(strtolower($iconReference), 'svg')) {
+            return SvgIconProvider::class;
+        } else {
+            return BitmapIconProvider::class;
+        }
+    }
 }