From 0dd53aea02bd983eff301ca61d05f07ec4a4d526 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 7 Jul 2015 18:56:40 -0600 Subject: [PATCH] more robust active() and activeChild() methods to support multiple routes --- system/src/Grav/Common/Page/Page.php | 33 +++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index b0c884304..8f64059f2 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -1603,10 +1603,14 @@ class Page */ public function active() { - /** @var Uri $uri */ - $uri = self::getGrav()['uri']; - if ($this->url() == $uri->url()) { - return true; + $uri_path = self::getGrav()['uri']->path(); + $routes = self::getGrav()['pages']->routes(); + + if (isset($routes[$uri_path])) { + if ($routes[$uri_path] == $this->path()) { + return true; + } + } return false; } @@ -1619,19 +1623,18 @@ class Page */ public function activeChild() { - /** @var Uri $uri */ $uri = self::getGrav()['uri']; + $pages = self::getGrav()['pages']; + $uri_path = $uri->path(); + $routes = self::getGrav()['pages']->routes(); - // Special check when item is home - if ($this->home()) { - $paths = $uri->paths(); - $home = Pages::getHomeRoute(); - if (isset($paths[0]) && $paths[0] == $home) { - return true; - } - } else { - if (strpos($uri->url(), $this->url()) === 0) { - return true; + if (isset($routes[$uri_path])) { + $child_page = $pages->dispatch($uri->route())->parent(); + while (!$child_page->root()) { + if ($this->path() == $child_page->path()) { + return true; + } + $child_page = $child_page->parent(); } }