From 451dd51f29d951aa144e1f5cfd79c463cd19c4d9 Mon Sep 17 00:00:00 2001 From: Nensi Gjata Date: Fri, 9 Apr 2021 16:41:27 +0200 Subject: [PATCH] BugFix: Fixed some cases where the menu items were rendered despite the fact that the user didn't have the access rights. --- src/Core/Menu/MenuBase.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Core/Menu/MenuBase.php b/src/Core/Menu/MenuBase.php index 330a66e89..d8f0a8780 100644 --- a/src/Core/Menu/MenuBase.php +++ b/src/Core/Menu/MenuBase.php @@ -224,12 +224,16 @@ private function processMenu(array $menu, bool $child = false, string $type = se private function unsetDisabledItem(array &$menu): void { - foreach ($menu as $index => $menuItem) { + //Keep outside otherwise the variable references get lost due to unset call. + $firstKey = array_keys($menu)[0]; + $menuLength = count($menu); + + for ($i=$firstKey; $i<$menuLength; $i++) { //todo: transform item in menuItem - if (!$this->isEnabled($menuItem) || !$menuItem['enable']) { - unset($menu[$index]); - } else if ($menuItem['submenu']) { - $this->unsetDisabledItem($menuItem['submenu']); + if (!$this->isEnabled($menu[$i]) || !$menu[$i]['enable']) { + unset($menu[$i]); + } else if ($menu[$i]['submenu']) { + $this->unsetDisabledItem($menu[$i]['submenu']); } } }