Commit 562b7c1d authored by Benni Mack's avatar Benni Mack Committed by Georg Ringer
Browse files

[TASK] Always use Icon API for Module Icons

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: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent 369334cf
......@@ -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'];
......
{namespace core = TYPO3\CMS\Core\ViewHelpers}
<f:layout name="Default" />
<f:section name="Content">
......@@ -28,10 +30,10 @@
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>
......
......@@ -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;
}
......
......@@ -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;
}
}
......@@ -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 = [
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment