From 6dd49761fffb3e6a173538418e54e56902dfd5ee Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 4 Sep 2015 16:21:09 +0200 Subject: [PATCH] Navigation: Add method getActiveItem() refs #5600 --- library/Icinga/Web/Navigation/Navigation.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/library/Icinga/Web/Navigation/Navigation.php b/library/Icinga/Web/Navigation/Navigation.php index 2cf4376fa..408576f3c 100644 --- a/library/Icinga/Web/Navigation/Navigation.php +++ b/library/Icinga/Web/Navigation/Navigation.php @@ -221,6 +221,23 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate return isset($this->items[$name]) ? $this->items[$name] : $default; } + /** + * Return the currently active item or the first one if none is active + * + * @return NavigationItem + */ + public function getActiveItem() + { + $firstItem = reset($this->items); + foreach ($this->items as $item) { + if ($item->getActive()) { + return $item; + } + } + + return $firstItem->setActive(); + } + /** * Return this navigation's items *