Add Font Awesome 6 support for user menu items
authorAlexander Ebert <ebert@woltlab.com>
Mon, 22 Aug 2022 14:02:51 +0000 (16:02 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 22 Aug 2022 14:02:51 +0000 (16:02 +0200)
XSD/userMenu.xsd
com.woltlab.wcf/templates/pageHeaderUser.tpl
com.woltlab.wcf/userMenu.xml
wcfsetup/install/files/lib/data/user/menu/item/UserMenuItem.class.php
wcfsetup/install/files/lib/system/package/plugin/UserMenuPackageInstallationPlugin.class.php

index 9421a9c8e6f617eaadb60d7b356d11b5dfe456f7..30bf104066bab7ec6c8c88f4c2f14f0d95477b27 100644 (file)
                <xs:attribute name="name" type="woltlab_varchar" use="required" />
        </xs:complexType>
        
+       <xs:complexType name="usermenuitem_icon">
+               <xs:attribute name="solid" type="xs:boolean" />
+       </xs:complexType>
+
        <!-- imported/updated page menu item element -->
        <xs:complexType name="usermenuitem_import">
                <xs:complexContent>
@@ -42,7 +46,7 @@
                                        <xs:element name="permissions" type="xs:string" minOccurs="0" />
                                        <xs:element name="controller" type="woltlab_varchar_nullable" minOccurs="0" />
                                        <xs:element name="iconclassname" type="woltlab_varchar_nullable" minOccurs="0" />
-                                       <xs:element name="classname" type="woltlab_varchar_nullable" minOccurs="0" />
+                                       <xs:element name="classname" type="usermenuitem_icon" minOccurs="0" />
                                        <xs:element name="parent" type="woltlab_varchar_nullable" minOccurs="0" />
                                        <xs:element name="showorder" type="xs:unsignedInt" minOccurs="0" />
                                </xs:all>
index af5a5e871356cf80cd4f1890318f385d21113d8b..3326fa39692f2e1acbfb87d2f08fbc5a45f6a76d 100644 (file)
@@ -74,7 +74,7 @@
                                                {foreach from=$__wcf->getUserMenu()->getUserMenuItems() item=menuItem}
                                                <div class="userMenuItem userMenuItemNarrow userMenuItemSingleLine" data-category="{$menuItem[category]->menuItem}">
                                                        <div class="userMenuItemImage">
-                                                               <span class="icon icon32 {$menuItem[category]->getIconClassName()}"></span>
+                                                               {@$menuItem[category]->getIcon()->toHtml(32)}
                                                        </div>
                                                        <div class="userMenuItemContent">
                                                                <a href="{$menuItem[link]}" class="userMenuItemLink">
index b85053cf66171f6b0bb125df20c5279722f2d6ef..7b67ef8ddc2d7bd2cd554a999f9ae25181ec9b91 100644 (file)
@@ -4,7 +4,7 @@
                <!-- profile -->
                <usermenuitem name="wcf.user.menu.profile">
                        <showorder>1</showorder>
-                       <iconclassname>fa-user</iconclassname>
+                       <iconclassname>user</iconclassname>
                </usermenuitem>
                <usermenuitem name="wcf.user.menu.profile.accountManagement">
                        <controller>wcf\form\AccountManagementForm</controller>
@@ -32,7 +32,7 @@
                <!-- settings -->
                <usermenuitem name="wcf.user.menu.settings">
                        <showorder>2</showorder>
-                       <iconclassname>fa-cog</iconclassname>
+                       <iconclassname>cog</iconclassname>
                </usermenuitem>
                <usermenuitem name="wcf.user.menu.settings.notification">
                        <controller>wcf\form\NotificationSettingsForm</controller>
@@ -48,7 +48,7 @@
                <!-- community -->
                <usermenuitem name="wcf.user.menu.community">
                        <showorder>3</showorder>
-                       <iconclassname>fa-globe</iconclassname>
+                       <iconclassname>globe</iconclassname>
                </usermenuitem>
                <usermenuitem name="wcf.user.menu.community.following">
                        <controller>wcf\page\FollowingPage</controller>
index 87ddbf70fd268908ddb463979d4a20666d5d1a72..443d4eb722b59d8c47922a6a6e89b4bdae5b2688 100644 (file)
@@ -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);
     }
 }
index 8c8d776c93fa0fd28dfe5a6849ac9befb8252331..9be42ed2466cfd0eec1c712f2470f609b6f4d9ff 100644 (file)
@@ -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