[TASK] Always use Icon API for Module Icons 74/46174/6
authorBenni Mack <benni@typo3.org>
Sat, 23 Jan 2016 11:58:55 +0000 (12:58 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Tue, 9 Feb 2016 07:33:19 +0000 (08:33 +0100)
The Icon API with icon identifiers is now used throughout the
core when rendering module icons. This avoids some additional
custom code on several places to identify backpaths etc.

Resolves: #73186
Releases: master
Change-Id: Ic146017a25e5872d0f835e7aae5ff6f00755926c
Reviewed-on: https://review.typo3.org/46174
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/about/Classes/Controller/ModulesController.php
typo3/sysext/about/Resources/Private/Templates/Modules/Index.html
typo3/sysext/backend/Classes/Backend/ToolbarItems/ShortcutToolbarItem.php
typo3/sysext/backend/Classes/Domain/Repository/Module/BackendModuleRepository.php
typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php

index 37ce64e..09cd4f3 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\About\Controller;
 use TYPO3\CMS\Backend\Module\ModuleLoader;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\View\BackendTemplateView;
+use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
@@ -144,7 +145,8 @@ class ModulesController extends ActionController
             $subModuleKey = $moduleName . '_' . $subModuleName . '_tab';
             $subModuleData = array();
             $subModuleData['name'] = $subModuleName;
-            $subModuleData['icon'] = PathUtility::getAbsoluteWebPath($subModuleInfo['icon']);
+            $subModuleData['icon'] = $subModuleInfo['icon'];
+            $subModuleData['iconIdentifier'] = $subModuleInfo['iconIdentifier'];
             $subModuleData['label'] = $this->languageService->moduleLabels['tabs'][$subModuleKey];
             $subModuleData['shortDescription'] = $this->languageService->moduleLabels['labels'][$subModuleKey . 'label'];
             $subModuleData['longDescription'] = $this->languageService->moduleLabels['labels'][$subModuleKey . 'descr'];
index a2385d4..b1b7f46 100644 (file)
@@ -1,3 +1,5 @@
+{namespace core = TYPO3\CMS\Core\ViewHelpers}
+
 <f:layout name="Default" />
 
 <f:section name="Content">
                                                                                title="{subModule.shortDescription}"
                                                                                class="pull-left"
                                                                        >
-                                                                               <span class="typo3-app-icon">
+                                                                               <span class="typo3-app-icon media-object" title="{subModule.label}">
                                                                                        <span>
                                                                                                <span>
-                                                                                                       <img src="../{subModule.icon}" alt="{subModule.label}" class="media-object" />
+                                                                                                       <core:icon identifier="{subModule.iconIdentifier}" size="default" />
                                                                                                </span>
                                                                                        </span>
                                                                                </span>
index 18bb512..d6c6439 100644 (file)
@@ -844,19 +844,18 @@ class ShortcutToolbarItem implements ToolbarItemInterface
                 $icon = '<span title="' . $titleAttribute . '">' . $this->iconFactory->getIcon('mimetypes-word', Icon::SIZE_SMALL)->render() . '</span>';
                 break;
             default:
+                $iconIdentifier = '';
                 $moduleName = $row['module_name'];
                 if (strpos($moduleName, '_') !== false) {
                     list($mainModule, $subModule) = explode('_', $moduleName, 2);
-                    $icon = $this->moduleLoader->modules[$mainModule]['sub'][$subModule]['icon'];
+                    $iconIdentifier = $this->moduleLoader->modules[$mainModule]['sub'][$subModule]['iconIdentifier'];
                 } elseif (!empty($moduleName)) {
-                    $icon = $this->moduleLoader->modules[$moduleName]['icon'];
+                    $iconIdentifier = $this->moduleLoader->modules[$moduleName]['iconIdentifier'];
                 }
-                if (!empty($icon) && file_exists($icon)) {
-                    $icon = '../' . PathUtility::stripPathSitePrefix($icon);
-                    $icon = '<img src="' . htmlspecialchars($icon) . '" alt="' . $titleAttribute . '" width="16">';
-                } else {
-                    $icon = '<span title="' . $titleAttribute . '">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
+                if (!$iconIdentifier) {
+                    $iconIdentifier = 'empty-empty';
                 }
+                $icon = '<span title="' . $titleAttribute . '">' . $this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render() . '</span>';
         }
         return $icon;
     }
index 07a82fc..24fee0d 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Domain\Repository\Module;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
+use TYPO3\CMS\Core\Imaging\IconRegistry;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 
@@ -255,7 +256,7 @@ class BackendModuleRepository implements \TYPO3\CMS\Core\SingletonInterface
                 'name' => $moduleName,
                 'title' => $GLOBALS['LANG']->moduleLabels['tabs'][$moduleName . '_tab'],
                 'onclick' => 'top.goToModule(' . GeneralUtility::quoteJSvalue($moduleName) . ');',
-                'icon' => $this->getModuleIcon($moduleName . '_tab', $moduleData),
+                'icon' => $this->getModuleIcon($moduleKey, $moduleData),
                 'link' => $moduleLink,
                 'description' => $GLOBALS['LANG']->moduleLabels['labels'][$moduleKey . 'label']
             );
@@ -265,7 +266,7 @@ class BackendModuleRepository implements \TYPO3\CMS\Core\SingletonInterface
                     'name' => $moduleName,
                     'title' => $GLOBALS['LANG']->moduleLabels['tabs'][$moduleName . '_tab'],
                     'onclick' => 'top.goToModule(' . GeneralUtility::quoteJSvalue($moduleName) . ');',
-                    'icon' => $this->getModuleIcon($moduleName . '_tab', $moduleData),
+                    'icon' => $this->getModuleIcon($moduleKey, $moduleData),
                     'link' => $moduleLink,
                     'originalLink' => $moduleLink,
                     'description' => $GLOBALS['LANG']->moduleLabels['labels'][$moduleKey . 'label'],
@@ -288,7 +289,7 @@ class BackendModuleRepository implements \TYPO3\CMS\Core\SingletonInterface
                         'name' => $moduleName . '_' . $submoduleName,
                         'title' => $GLOBALS['LANG']->moduleLabels['tabs'][$submoduleKey],
                         'onclick' => 'top.goToModule(' . GeneralUtility::quoteJSvalue($moduleName . '_' . $submoduleName) . ');',
-                        'icon' => $this->getModuleIcon($submoduleKey, $submoduleData),
+                        'icon' => $this->getModuleIcon($moduleKey, $submoduleData),
                         'link' => $submoduleLink,
                         'originalLink' => $originalLink,
                         'description' => $submoduleDescription,
@@ -340,7 +341,7 @@ class BackendModuleRepository implements \TYPO3\CMS\Core\SingletonInterface
     }
 
     /**
-     * gets the module icon and its size
+     * gets the module icon
      *
      * @param string $moduleKey Module key
      * @param array $moduleData the compiled data associated with it
@@ -348,17 +349,15 @@ class BackendModuleRepository implements \TYPO3\CMS\Core\SingletonInterface
      */
     protected function getModuleIcon($moduleKey, $moduleData)
     {
-        $icon = '';
-
-        // add as a sprite icon
-        if (!empty($moduleData['iconIdentifier'])) {
+        $iconIdentifier = !(empty($moduleData['iconIdentifier']))
+            ? $moduleData['iconIdentifier']
+            : 'module-icon-' . $moduleKey;
+        $iconRegisty = GeneralUtility::makeInstance(IconRegistry::class);
+        if ($iconRegisty->isRegistered($iconIdentifier)) {
             $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
-            $icon = $iconFactory->getIcon($moduleData['iconIdentifier'])->render();
-        } elseif (isset($moduleData['icon']) && is_file($moduleData['icon'])) {
-            $iconTitle = $GLOBALS['LANG']->moduleLabels['tabs'][$moduleKey];
-            $iconSizes = @getimagesize($moduleData['icon']);
-            $icon = '<img src="' . PathUtility::getAbsoluteWebPath($moduleData['icon']) . '" ' . $iconSizes[3] . ' title="' . htmlspecialchars($iconTitle) . '" alt="' . htmlspecialchars($iconTitle) . '" />';
+            return $iconFactory->getIcon($iconIdentifier)->render();
+        } else {
+            return '';
         }
-        return $icon;
     }
 }
index 47f0370..7d815e9 100644 (file)
@@ -312,12 +312,13 @@ abstract class AbstractItemProvider
                         // Icon:
                         if (strpos($theMod, '_') !== false) {
                             list($mainModule, $subModule) = explode('_', $theMod, 2);
-                            $icon = $loadModules->modules[$mainModule]['sub'][$subModule]['icon'];
+                            $icon = $loadModules->modules[$mainModule]['sub'][$subModule]['iconIdentifier'];
                         } else {
-                            $icon = $loadModules->modules[$theMod]['icon'];
+                            $icon = $loadModules->modules[$theMod]['iconIdentifier'];
                         }
                         if ($icon) {
-                            $icon = '../' . PathUtility::stripPathSitePrefix($icon);
+                            $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
+                            $icon = $iconFactory->getIcon($icon)->render();
                         }
                         // Add help text
                         $helpText = [
index f0aed13..ded7cc0 100644 (file)
@@ -15,6 +15,9 @@ namespace TYPO3\CMS\Core\Utility;
  */
 
 use TYPO3\CMS\Core\Category\CategoryRegistry;
+use TYPO3\CMS\Core\Imaging\IconFactory;
+use TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider;
+use TYPO3\CMS\Core\Imaging\IconRegistry;
 use TYPO3\CMS\Core\Migrations\TcaMigration;
 use TYPO3\CMS\Core\Package\PackageManager;
 
@@ -871,8 +874,15 @@ class ExtensionManagementUtility
             unset($moduleConfiguration['labels']['tabs_images']['tab']);
         }
 
+        // Register the icon and move it too "iconIdentifier"
         if (!empty($moduleConfiguration['icon'])) {
-            $moduleConfiguration['icon'] = GeneralUtility::getFileAbsFileName($moduleConfiguration['icon'], false, true);
+            $iconIdentifier = 'module-' . $moduleSignature;
+            $iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
+            $iconRegistry->registerIcon($iconIdentifier, BitmapIconProvider::class, [
+                'source' => GeneralUtility::getFileAbsFileName($moduleConfiguration['icon'], false, true)
+            ]);
+            $moduleConfiguration['iconIdentifier'] = $iconIdentifier;
+            unset($moduleConfiguration['icon']);
         }
 
         $moduleLabels = array(
@@ -944,7 +954,13 @@ class ExtensionManagementUtility
             }
 
             if (!empty($moduleConfiguration['icon'])) {
-                $moduleConfiguration['icon'] = GeneralUtility::getFileAbsFileName($moduleConfiguration['icon'], false, true);
+                $iconIdentifier = 'module-' . $fullModuleSignature;
+                $iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
+                $iconRegistry->registerIcon($iconIdentifier, BitmapIconProvider::class, [
+                    'source' => GeneralUtility::getFileAbsFileName($moduleConfiguration['icon'], false, true)
+                ]);
+                $moduleConfiguration['iconIdentifier'] = $iconIdentifier;
+                unset($moduleConfiguration['icon']);
             }
 
             $GLOBALS['TBE_MODULES']['_configuration'][$fullModuleSignature] = $moduleConfiguration;