Navigation: Add method getActiveItem()

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-04 16:21:09 +02:00
parent 6967fffb1f
commit 6dd49761ff
1 changed files with 17 additions and 0 deletions

View File

@ -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
*