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 *