/** * @param string $currentUri * * @return bool */ public function findActivePageByUri($currentUri) { $foundPages = []; $siteUrl = url()->current(); $pages = $this->getPages(); foreach ($pages as $page) { $url = $page->getUrl(); $len = strpos($url, $siteUrl); if ($len !== false) { $len += strlen($siteUrl); } $url = substr($url, $len); $len = strpos($currentUri, $siteUrl); if ($len !== false) { $len += strlen($siteUrl); } if (!empty($url)) { $uri = substr($currentUri, $len); $pos = strpos($uri, $url); if ($pos !== false) { $foundPages[strlen(substr($uri, strlen($url)))] = $page; $page->setStatus(true); } } } if (count($foundPages) > 0) { ksort($foundPages); $page = array_shift($foundPages); $this->navigation->setCurrentPage($page); } foreach ($this->getSections() as $section) { $section->findActivePageByUri($currentUri); } }
/** * @param Navigation $navigation */ public function buildMenu(Navigation $navigation) { $section = $navigation->addSection('SleepingOwl', null, 999); $section->setIcon('cubes'); foreach ($this->menuItems as $item) { $section->addPage($item); } }