Add support for brand icons for `userMenu.xml`
authorAlexander Ebert <ebert@woltlab.com>
Mon, 18 Sep 2023 17:24:06 +0000 (19:24 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 18 Sep 2023 17:24:06 +0000 (19:24 +0200)
See https://www.woltlab.com/community/thread/301652-brand-icons-in-usemenu-xml-verwenden/

wcfsetup/install/files/lib/data/user/menu/item/UserMenuItem.class.php
wcfsetup/install/files/lib/system/package/plugin/UserMenuPackageInstallationPlugin.class.php

index f8bac02f680487f64bab9420e434078f6de6f4a3..4e4a2ee0ccddacafe58e54dde2da45db5287a915 100644 (file)
@@ -10,6 +10,8 @@ use wcf\system\menu\user\IUserMenuItemProvider;
 use wcf\system\Regex;
 use wcf\system\request\LinkHandler;
 use wcf\system\style\FontAwesomeIcon;
+use wcf\system\style\FontAwesomeIconBrand;
+use wcf\system\style\IFontAwesomeIcon;
 use wcf\system\WCF;
 
 /**
@@ -150,10 +152,14 @@ class UserMenuItem extends ProcessibleDatabaseObject implements ITitledObject, I
     /**
      * @since 6.0
      */
-    public function getIcon(): ?FontAwesomeIcon
+    public function getIcon(): ?IFontAwesomeIcon
     {
         if ($this->iconClassName && !\str_starts_with($this->iconClassName, 'fa-')) {
-            return FontAwesomeIcon::fromString($this->iconClassName);
+            if (\str_starts_with($this->iconClassName, '@brand:')) {
+                return FontAwesomeIconBrand::fromName(\substr($this->iconClassName, 7));
+            } else {
+                return FontAwesomeIcon::fromString($this->iconClassName);
+            }
         }
 
         return FontAwesomeIcon::fromValues('bars');
index b126338057011732a662aa74e55f3ee2c522910f..dfd8296d9161c0d6dce2b45f2ca8afead0410c6b 100644 (file)
@@ -64,12 +64,20 @@ class UserMenuPackageInstallationPlugin extends AbstractMenuPackageInstallationP
     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'
-            );
+            $isBrandIcon = $element->getAttribute('type') === 'brand';
+            if ($isBrandIcon) {
+                $elements['iconClassName'] = \sprintf(
+                    "@brand:%s",
+                    $element->nodeValue,
+                );
+            } else {
+                $solid = $element->getAttribute('solid');
+                $elements['iconClassName'] = \sprintf(
+                    "%s;%s",
+                    $element->nodeValue,
+                    $solid === 'true' ? 'true' : 'false'
+                );
+            }
         } else {
             $elements[$element->tagName] = $element->nodeValue;
         }