From 0a99288bca2b8faafd7992df79df5c61ad672379 Mon Sep 17 00:00:00 2001 From: Fabian Schmid Date: Thu, 17 Feb 2022 14:46:56 +0100 Subject: [PATCH] fixed some display errors in MM administration # Conflicts: # src/GlobalScreen/Scope/MainMenu/Collector/MainMenuMainCollector.php --- .../Facade/class.ilMMAbstractItemFacade.php | 7 ++++--- .../Collector/MainMenuMainCollector.php | 21 ++++++++++++------- .../Scope/MainMenu/Collector/Map/Map.php | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Services/MainMenu/classes/Items/Facade/class.ilMMAbstractItemFacade.php b/Services/MainMenu/classes/Items/Facade/class.ilMMAbstractItemFacade.php index c50000f41643..03613a331eab 100644 --- a/Services/MainMenu/classes/Items/Facade/class.ilMMAbstractItemFacade.php +++ b/Services/MainMenu/classes/Items/Facade/class.ilMMAbstractItemFacade.php @@ -17,6 +17,7 @@ use ILIAS\GlobalScreen\Scope\MainMenu\Factory\TopItem\TopLinkItem; use ILIAS\GlobalScreen\Scope\MainMenu\Factory\TopItem\TopParentItem; use ILIAS\UI\Component\Link\Link; +use ILIAS\GlobalScreen\Scope\MainMenu\Factory\isParent; /** * Class ilMMAbstractItemFacade @@ -143,8 +144,8 @@ public function getFilteredItem() : isItem public function getAmountOfChildren() : int { - if ($this->raw_item instanceof \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isParent) { - return count($this->raw_item->getChildren()); + if ($this->filtered_item instanceof isParent) { + return count($this->filtered_item->getChildren()); } return 0; @@ -152,7 +153,7 @@ public function getAmountOfChildren() : int public function isAvailable() : bool { - return (bool) ($this->raw_item->isAvailable() || $this->raw_item->isAlwaysAvailable()); + return (bool) ($this->filtered_item->isAvailable() || $this->filtered_item->isAlwaysAvailable()); } /** diff --git a/src/GlobalScreen/Scope/MainMenu/Collector/MainMenuMainCollector.php b/src/GlobalScreen/Scope/MainMenu/Collector/MainMenuMainCollector.php index 89bcb3b38581..536d10d3f3f3 100644 --- a/src/GlobalScreen/Scope/MainMenu/Collector/MainMenuMainCollector.php +++ b/src/GlobalScreen/Scope/MainMenu/Collector/MainMenuMainCollector.php @@ -163,6 +163,16 @@ public function cleanupItemsForUIRepresentation() : void } return $item; }); + + $this->map->walk(static function (isItem &$i) : void { + if ($i instanceof isParent && count($i->getChildren()) === 0) { + $i = $i->withAvailableCallable(static function () { + return false; + })->withVisibilityCallable(static function () { + return false; + }); + } + }); // filter empty slates $this->map->filter(static function (isItem $i) : bool { @@ -172,6 +182,7 @@ public function cleanupItemsForUIRepresentation() : void return true; }); + } public function sortItemsForUIRepresentation() : void @@ -217,10 +228,7 @@ public function hasItems() : bool */ public function getSingleItemFromFilter(IdentificationInterface $identification) : isItem { - $item = $this->map->getSingleItemFromFilter($identification); - $this->map->add($item); - - return $item; + return $this->map->getSingleItemFromFilter($identification); } /** @@ -230,10 +238,7 @@ public function getSingleItemFromFilter(IdentificationInterface $identification) */ public function getSingleItemFromRaw(IdentificationInterface $identification) : isItem { - $item = $this->map->getSingleItemFromRaw($identification); - $this->map->add($item); - - return $item; + return $this->map->getSingleItemFromRaw($identification); } /** diff --git a/src/GlobalScreen/Scope/MainMenu/Collector/Map/Map.php b/src/GlobalScreen/Scope/MainMenu/Collector/Map/Map.php index a1f3381738bb..34bb88a3ae33 100644 --- a/src/GlobalScreen/Scope/MainMenu/Collector/Map/Map.php +++ b/src/GlobalScreen/Scope/MainMenu/Collector/Map/Map.php @@ -156,7 +156,7 @@ public function getAllFromFilter() : \Iterator public function walk(Closure $c) : void { $this->applyFilters(); - $to_walk = (array) $this->filtered; + $to_walk = (array) $this->filtered->getArrayCopy(); array_walk($to_walk, $c); $this->filtered = new ArrayObject($to_walk); }