Skip to content

Commit

Permalink
Use FontAwesomeIcon to provide an icon for menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntimeX committed May 2, 2024
1 parent 0ae6ebc commit c2e80cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
14 changes: 13 additions & 1 deletion wcfsetup/install/files/lib/system/menu/acp/ACPMenu.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use wcf\system\menu\acp\event\AcpMenuCollecting;
use wcf\system\menu\ITreeMenuItem;
use wcf\system\menu\TreeMenu;
use wcf\system\style\FontAwesomeIcon;
use wcf\system\WCF;

/**
Expand Down Expand Up @@ -77,12 +78,23 @@ private function loadLegacyMenuItems(): void
continue;
}

$icon = null;
if ($item->icon) {
if (FontAwesomeIcon::isValidString($item->icon)) {
$icon = FontAwesomeIcon::fromString($item->icon);
} elseif (\str_starts_with($item->icon, 'fa-')) {
// Safeguard to prevent legacy icons from breaking
// the admin panel during the upgrade to 6.0.
$icon = FontAwesomeIcon::fromString("question;true");
}
}

$this->menuItems[$parentMenuItem][] = new AcpMenuItem(
$item->menuItem,
$item->__toString(),
$item->parentMenuItem,
$item->getLink(),
$item->icon ?? ''
$icon
);
}
}
Expand Down
14 changes: 2 additions & 12 deletions wcfsetup/install/files/lib/system/menu/acp/AcpMenuItem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
public readonly string $title = '',
public readonly string $parentMenuItem = '',
public readonly string $link = '',
public readonly string $icon = ''
public readonly ?FontAwesomeIcon $icon = null
) {
}

Expand All @@ -32,17 +32,7 @@ public function getLink()

public function getIcon(): ?FontAwesomeIcon
{
if ($this->icon) {
if (FontAwesomeIcon::isValidString($this->icon)) {
return FontAwesomeIcon::fromString($this->icon);
} elseif (\str_starts_with($this->icon, 'fa-')) {
// Safeguard to prevent legacy icons from breaking
// the admin panel during the upgrade to 6.0.
return FontAwesomeIcon::fromString("question;true");
}
}

return null;
return $this->icon;
}

public function __toString()
Expand Down

0 comments on commit c2e80cd

Please sign in to comment.