NavigationItem: Automatically determine whether it's active or not

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-04 10:10:33 +02:00
parent baefc89f85
commit 07588595f2
1 changed files with 15 additions and 1 deletions

View File

@ -149,7 +149,21 @@ class NavigationItem implements IteratorAggregate
*/
public function getActive()
{
return $this->active ?: false;
if ($this->active === null) {
$this->active = false;
if ($this->getUrl() !== null && Icinga::app()->getRequest()->getUrl()->matches($this->getUrl())) {
$this->setActive();
} elseif ($this->hasChildren()) {
foreach ($this->getChildren() as $item) {
/** @var NavigationItem $item */
if ($item->getActive()) {
// Do nothing, a true active state is automatically passed to all parents
}
}
}
}
return $this->active;
}
/**