From 2a37d0d2e83276d3034edc827149e1cc7a4ad019 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 22 Aug 2022 16:02:51 +0200 Subject: [PATCH] Add Font Awesome 6 support for user menu items --- XSD/userMenu.xsd | 6 ++++- com.woltlab.wcf/templates/pageHeaderUser.tpl | 2 +- com.woltlab.wcf/userMenu.xml | 6 ++--- .../user/menu/item/UserMenuItem.class.php | 16 ++++++++---- ...serMenuPackageInstallationPlugin.class.php | 25 ++++++++++++++----- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/XSD/userMenu.xsd b/XSD/userMenu.xsd index 9421a9c8e6..30bf104066 100644 --- a/XSD/userMenu.xsd +++ b/XSD/userMenu.xsd @@ -33,6 +33,10 @@ + + + + @@ -42,7 +46,7 @@ - + diff --git a/com.woltlab.wcf/templates/pageHeaderUser.tpl b/com.woltlab.wcf/templates/pageHeaderUser.tpl index af5a5e8713..3326fa3969 100644 --- a/com.woltlab.wcf/templates/pageHeaderUser.tpl +++ b/com.woltlab.wcf/templates/pageHeaderUser.tpl @@ -74,7 +74,7 @@ {foreach from=$__wcf->getUserMenu()->getUserMenuItems() item=menuItem}
- + {@$menuItem[category]->getIcon()->toHtml(32)}
diff --git a/com.woltlab.wcf/userMenu.xml b/com.woltlab.wcf/userMenu.xml index b85053cf66..7b67ef8ddc 100644 --- a/com.woltlab.wcf/userMenu.xml +++ b/com.woltlab.wcf/userMenu.xml @@ -4,7 +4,7 @@ 1 - fa-user + user wcf\form\AccountManagementForm @@ -32,7 +32,7 @@ 2 - fa-cog + cog wcf\form\NotificationSettingsForm @@ -48,7 +48,7 @@ 3 - fa-globe + globe wcf\page\FollowingPage diff --git a/wcfsetup/install/files/lib/data/user/menu/item/UserMenuItem.class.php b/wcfsetup/install/files/lib/data/user/menu/item/UserMenuItem.class.php index 87ddbf70fd..443d4eb722 100644 --- a/wcfsetup/install/files/lib/data/user/menu/item/UserMenuItem.class.php +++ b/wcfsetup/install/files/lib/data/user/menu/item/UserMenuItem.class.php @@ -4,11 +4,15 @@ namespace wcf\data\user\menu\item; use wcf\data\ITitledObject; use wcf\data\ProcessibleDatabaseObject; +use wcf\system\exception\SystemException; use wcf\system\menu\ITreeMenuItem; use wcf\system\menu\user\DefaultUserMenuItemProvider; use wcf\system\menu\user\IUserMenuItemProvider; use wcf\system\Regex; use wcf\system\request\LinkHandler; +use wcf\system\style\exception\InvalidIconFormat; +use wcf\system\style\exception\UnknownIcon; +use wcf\system\style\FontAwesomeIcon; use wcf\system\WCF; /** @@ -150,12 +154,14 @@ class UserMenuItem extends ProcessibleDatabaseObject implements ITitledObject, I } /** - * Returns FontAwesome icon class name. - * - * @return string + * @since 6.0 */ - public function getIconClassName() + public function getIcon(): ?FontAwesomeIcon { - return $this->iconClassName ?: 'fa-bars'; + if ($this->iconClassName && !\str_starts_with($this->iconClassName, 'fa-')) { + return FontAwesomeIcon::fromString($this->iconClassName); + } + + return FontAwesomeIcon::fromValues('bars', false); } } diff --git a/wcfsetup/install/files/lib/system/package/plugin/UserMenuPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/UserMenuPackageInstallationPlugin.class.php index 8c8d776c93..9be42ed246 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/UserMenuPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/UserMenuPackageInstallationPlugin.class.php @@ -52,17 +52,30 @@ class UserMenuPackageInstallationPlugin extends AbstractMenuPackageInstallationP $result['className'] = $data['elements']['classname']; } - // FontAwesome icon name - if ( - !empty($data['elements']['iconclassname']) - && \preg_match('~^fa\-[a-z\-]+$~', $data['elements']['iconclassname']) - ) { - $result['iconClassName'] = $data['elements']['iconclassname']; + if (isset($data['elements']['iconClassName'])) { + $result['iconClassName'] = $data['elements']['iconClassName']; } return $result; } + /** + * @inheritDoc + */ + protected function getElement(\DOMXPath $xpath, array &$elements, \DOMElement $element) + { + if ($element->tagName === 'iconclassname') { + $solid = $element->getAttribute('solid'); + $elements['iconClassName'] = \sprintf( + "%s;%s", + $element->nodeValue, + $solid === 'true' ? 'true' : 'false' + ); + } else { + $elements[$element->tagName] = $element->nodeValue; + } + } + /** * @inheritDoc * @since 5.2 -- 2.20.1