From: Matthias Schmidt Date: Fri, 22 May 2020 11:35:15 +0000 (+0200) Subject: Hide empty user option categories in user menu (#3294) X-Git-Tag: 5.3.0_Alpha_1~281 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f2d501fbb987b18576c80c1e38a36fa4225e8d51;p=GitHub%2FWoltLab%2FWCF.git Hide empty user option categories in user menu (#3294) * Hide empty user option categories in user menu Close #3280 * Fix typo in documentation Co-authored-by: Alexander Ebert Co-authored-by: Alexander Ebert --- diff --git a/wcfsetup/install/files/lib/form/SettingsForm.class.php b/wcfsetup/install/files/lib/form/SettingsForm.class.php index 966fb83e72..4d6c61e62f 100644 --- a/wcfsetup/install/files/lib/form/SettingsForm.class.php +++ b/wcfsetup/install/files/lib/form/SettingsForm.class.php @@ -130,6 +130,9 @@ class SettingsForm extends AbstractForm { Trophy::sort($this->availableTrophies, 'showOrder'); } + else if (empty($this->optionHandler->getOptionTree())) { + throw new IllegalLinkException(); + } } /** diff --git a/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php b/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php index 49913a9a8c..4a49f30bf8 100644 --- a/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php @@ -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(); } }