From f5a450bda4a871af28ec4e50077a86ce9866c7a2 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 14 Jan 2020 15:17:28 +0100 Subject: [PATCH] add method to remove MenuItem from menu (#113) --- Event/MenuEvent.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Event/MenuEvent.php b/Event/MenuEvent.php index 10092be..ccf9970 100644 --- a/Event/MenuEvent.php +++ b/Event/MenuEvent.php @@ -62,6 +62,21 @@ public function addItem($item) return $this; } + /** + * @param MenuItemInterface|MenuItem|string $item + * @return MenuEvent + */ + public function removeItem($item): MenuEvent + { + if ($item instanceof MenuItemInterface && isset($this->menuRootItems[$item->getIdentifier()])) { + unset($this->menuRootItems[$item->getIdentifier()]); + } elseif (is_string($item) && isset($this->menuRootItems[$item])) { + unset($this->menuRootItems[$item]); + } + + return $this; + } + /** * @param string $id * @return MenuItemInterface|MenuItem|null