Skip to content

Commit

Permalink
[BUGFIX] Fix issues around icon processing
Browse files Browse the repository at this point in the history
* Preserves icon identifiers as value of "icon" option
* Returns already registered icon identifiers directly
* Registers icons with Icon::SIZE_DEFAULT

Close: #2032
Close: #2049
  • Loading branch information
NamelessCoder committed Aug 14, 2023
1 parent cebbe4f commit 700c9fc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
5 changes: 0 additions & 5 deletions Classes/Builder/ContentTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,6 @@ protected function addIcon(Form $form, string $contentType): string
return $GLOBALS['TCA']['tt_content']['ctrl']['typeicon_classes'][$contentType];
}
$icon = MiscellaneousUtility::getIconForTemplate($form);
if (!empty($icon)) {
if (strpos($icon, 'EXT:') === 0 || $icon[0] !== '/') {
$icon = GeneralUtility::getFileAbsFileName($icon);
}
}
if (!$icon) {
$icon = ExtensionManagementUtility::extPath('flux', 'Resources/Public/Icons/Extension.svg');
}
Expand Down
3 changes: 3 additions & 0 deletions Classes/Form/Field/ControllerActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ protected function buildItemsForActions(array $actions): array
return $items;
}

/**
* @codeCoverageIgnore
*/
protected function resolvePathToFileInExtension(string $extensionKey, string $path): string
{
return ExtensionManagementUtility::extPath($extensionKey, $path);
Expand Down
15 changes: 12 additions & 3 deletions Classes/Utility/MiscellaneousUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ public static function getIconForTemplate(Form $form): ?string
*/
public static function createIcon(string $originalFile, ?string $identifier = null): string
{
/** @var IconRegistry $iconRegistry */
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
if ($iconRegistry->isRegistered($originalFile)) {
return $originalFile;
}

if (strpos($originalFile, 'EXT:') === 0 || $originalFile[0] !== '/') {
$originalFile = GeneralUtility::getFileAbsFileName($originalFile);
}

$extension = pathinfo($originalFile, PATHINFO_EXTENSION);
switch (strtolower($extension)) {
case 'svg':
Expand All @@ -92,13 +102,12 @@ public static function createIcon(string $originalFile, ?string $identifier = nu
default:
$iconProvider = BitmapIconProvider::class;
}

$iconIdentifier = $identifier ?? 'icon-' . md5($originalFile);
/** @var IconRegistry $iconRegistry */
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
$iconRegistry->registerIcon(
$iconIdentifier,
$iconProvider,
['source' => $originalFile, 'size' => Icon::SIZE_LARGE]
['source' => $originalFile, 'size' => Icon::SIZE_DEFAULT]
);
return $iconIdentifier;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/Utility/MiscellaneousUtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function testCreateIcon()
$graphicsClassName = 'TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][$graphicsClassName]['className'] =
'FluidTYPO3\\Flux\\Tests\\Fixtures\\Classes\\DummyGraphicalFunctions';
$this->assertEquals('icon-b7c9dc75b2c29a9a52e8c1f7a996348b', MiscellaneousUtility::createIcon('foobar-icon'));
$this->assertEquals('foobar-icon', MiscellaneousUtility::createIcon('foobar-icon'));
}

/**
Expand All @@ -139,7 +139,7 @@ public function testCreateIconWithCustomIdentifier()
$graphicsClassName = 'TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][$graphicsClassName]['className'] =
'FluidTYPO3\\Flux\\Tests\\Fixtures\\Classes\\DummyGraphicalFunctions';
$this->assertEquals('icon-identifier', MiscellaneousUtility::createIcon('foobar-icon', 'icon-identifier'));
$this->assertEquals('foobar-icon', MiscellaneousUtility::createIcon('foobar-icon', 'icon-identifier'));
}

/**
Expand Down

0 comments on commit 700c9fc

Please sign in to comment.