From 07588595f284d6093e3e6d2a31752d07047116db Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 4 Sep 2015 10:10:33 +0200 Subject: [PATCH] NavigationItem: Automatically determine whether it's active or not refs #5600 --- library/Icinga/Web/Navigation/NavigationItem.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Web/Navigation/NavigationItem.php b/library/Icinga/Web/Navigation/NavigationItem.php index f26b007fd..9b7e5e8fa 100644 --- a/library/Icinga/Web/Navigation/NavigationItem.php +++ b/library/Icinga/Web/Navigation/NavigationItem.php @@ -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; } /**