Hide empty user option categories in user menu (#3294)
authorMatthias Schmidt <gravatronics@live.com>
Fri, 22 May 2020 11:35:15 +0000 (13:35 +0200)
committerGitHub <noreply@github.com>
Fri, 22 May 2020 11:35:15 +0000 (13:35 +0200)
* Hide empty user option categories in user menu

Close #3280

* Fix typo in documentation

Co-authored-by: Alexander Ebert <ebert@woltlab.com>
Co-authored-by: Alexander Ebert <ebert@woltlab.com>
wcfsetup/install/files/lib/form/SettingsForm.class.php
wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php

index 966fb83e7282d333e43946dd7329e779545786b7..4d6c61e62fc60970e0f209c57c6ba7e00d8be850 100644 (file)
@@ -130,6 +130,9 @@ class SettingsForm extends AbstractForm {
                        
                        Trophy::sort($this->availableTrophies, 'showOrder');
                }
+               else if (empty($this->optionHandler->getOptionTree())) {
+                       throw new IllegalLinkException();
+               }
        }
        
        /**
index 49913a9a8c8f8ae91ebcd337dbbbdbfdbe10a460..4a49f30bf80024bf2f25c9ca583d26a3a4a9e834 100644 (file)
@@ -4,6 +4,8 @@ use wcf\data\user\menu\item\UserMenuItem;
 use wcf\system\cache\builder\UserMenuCacheBuilder;
 use wcf\system\menu\ITreeMenuItem;
 use wcf\system\menu\TreeMenu;
+use wcf\system\option\user\UserOptionHandler;
+use wcf\system\WCF;
 
 /**
  * Builds the user menu.
@@ -14,6 +16,12 @@ use wcf\system\menu\TreeMenu;
  * @package    WoltLabSuite\Core\System\Menu\User
  */
 class UserMenu extends TreeMenu {
+       /**
+        * user option handler for the `settings` category
+        * @var UserOptionHandler
+        */
+       protected $optionHandler;
+       
        /**
         * @inheritDoc
         */
@@ -21,6 +29,8 @@ class UserMenu extends TreeMenu {
                parent::loadCache();
                
                $this->menuItems = UserMenuCacheBuilder::getInstance()->getData();
+               $this->optionHandler = new UserOptionHandler(false, '', 'settings');
+               $this->optionHandler->setUser(WCF::getUser());
        }
        
        /**
@@ -31,6 +41,14 @@ class UserMenu extends TreeMenu {
                
                if (!parent::checkMenuItem($item)) return false;
                
+               // Hide links to user option categories without accessible options.
+               if (strpos($item->menuItem, 'wcf.user.option.category.') === 0) {
+                       $categoryName = str_replace('wcf.user.option.category.', '', $item->menuItem);
+                       if (empty($this->optionHandler->getOptionTree($categoryName))) {
+                               return false;
+                       }
+               }
+               
                return $item->getProcessor()->isVisible();
        }
 }