/** * Set up the navigation items and assign them to the view * * @param Greengrape\Request $sitemap Sitemap object * @param string $uri Current URI * @param Greengrape\View $view View object * @return void */ public function setupNavigationItems(Request $request, $uri, View $view) { $mainNavigationCollection = new NavigationCollection($this->getContentDir(), $request->getBaseUrl()); foreach ($mainNavigationCollection as $item) { // If the first part of the URI matches this item's href then this // should be the active navigation item if (strpos($uri, $item->getHref()) === 0) { $item->setActive(true); $view->setActiveNavigationItem($item); } } $view->setNavigationItems($mainNavigationCollection); if (!$view->getActiveNavigationItem()) { // If we don't have an active navigation item, don't try to get the // sub navigation return false; } $subNavigationCollection = new NavigationCollection($this->getContentDir(), $request->getBaseUrl(), $view->getActiveNavigationItem()); foreach ($subNavigationCollection as $subItem) { // If the first part of the URI matches this item's href then this // should be the active navigation item if (strpos($uri, $subItem->getHref()) === 0) { $subItem->setActive(true); $view->setActiveSubNavigationItem($subItem); } } $view->setSubNavigationItems($subNavigationCollection); }