protected function decorateDropdown($content, \Zend\Navigation\Page\AbstractPage $page, $renderIcons = true, $activeIconInverse = true, array $options = array()) { //Get attribs $liAttribs = array('id' => $page->getId(), 'class' => 'dropdown' . ($page->isActive(true) ? ' active' : '')); $html = "\n" . '<li' . $this->htmlAttribs($liAttribs) . '>' . "\n" . $content . "\n</li>"; return $html; }
/** * Get list item class. * * @param AbstractPage $page * * @return string */ public function getLiClass(AbstractPage $page) { /* @var $escaper \Zend\View\Helper\EscapeHtmlAttr */ $escaper = $this->getView()->plugin('escapeHtmlAttr'); $liClasses = array($this->liClass); if ($this->getAddClassToListItem()) { $liClasses[] = $page->getClass(); } if ($page->hasPages()) { $liClasses[] = $this->getLiHasMenuClass(); } if ($page->isActive(true)) { $liClasses[] = $this->getLiActiveClass(); } return $escaper(implode(' ', $liClasses)); }
/** * Returns whether page should be considered active or not * * This method will compare the page properties against the request uri. * * @param bool $recursive * [optional] whether page should be considered * active if any child pages are active. Default is * false. * @return bool whether page should be considered active or not */ public function isActive($recursive = false) { if (!$this->active) { if ($this->getRequest() instanceof Request) { if ($this->getRequest()->getUri()->getPath() == $this->getUri()) { $this->active = true; return true; } } } return parent::isActive($recursive); }
/** * Returns whether page should be considered active or not * * This method will compare the page properties against the route matches * composed in the object. * * @param bool $recursive [optional] whether page should be considered * active if any child pages are active. Default is * false. * @return bool whether page should be considered active or not */ public function isActive($recursive = false) { if (!$this->active) { $reqParams = array(); if ($this->routeMatch instanceof RouteMatch) { $reqParams = $this->routeMatch->getParams(); if ($this->routeMatch->getMatchedRouteName() === $this->getRoute()) { $this->active = true; return true; } } $myParams = $this->params; if (null !== $this->controller) { $myParams['controller'] = $this->controller; } else { /** * @todo In ZF1, this was configurable and pulled from the front controller */ $myParams['controller'] = 'index'; } if (null !== $this->action) { $myParams['action'] = $this->action; } else { /** * @todo In ZF1, this was configurable and pulled from the front controller */ $myParams['action'] = 'action'; } if (count(array_intersect_assoc($reqParams, $myParams)) == count($myParams)) { $this->active = true; return true; } } return parent::isActive($recursive); }
/** * Returns whether page should be considered active or not * * This method will compare the page properties against the route matches * composed in the object. * * @param bool $recursive [optional] whether page should be considered * active if any child pages are active. Default is * false. * @return bool whether page should be considered active or not */ public function isActive($recursive = false) { if (!$this->active) { $reqParams = array(); if ($this->routeMatch instanceof RouteMatch) { $reqParams = $this->routeMatch->getParams(); if (isset($reqParams[ModuleRouteListener::ORIGINAL_CONTROLLER])) { $reqParams['controller'] = $reqParams[ModuleRouteListener::ORIGINAL_CONTROLLER]; } $pageParams = $this->params; if (null !== $this->controller) { $pageParams['controller'] = $this->controller; } if (null !== $this->action) { $pageParams['action'] = $this->action; } if (null !== $this->getRoute()) { if ($this->routeMatch->getMatchedRouteName() === $this->getRoute() && count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams)) { $this->active = true; return $this->active; } else { return parent::isActive($recursive); } } } $pageParams = $this->params; if (null !== $this->controller) { $pageParams['controller'] = $this->controller; } else { /** * @todo In ZF1, this was configurable and pulled from the front controller */ $pageParams['controller'] = 'index'; } if (null !== $this->action) { $pageParams['action'] = $this->action; } else { /** * @todo In ZF1, this was configurable and pulled from the front controller */ $pageParams['action'] = 'index'; } if (count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams)) { $this->active = true; return true; } } return parent::isActive($recursive); }
protected function renderDropdown(\Zend\Navigation\Page\AbstractPage $page, $renderIcons = true, $activeIconInverse = true, array $options = array()) { $class = $page->getClass(); $this->addWord('btn', $class); if ($page->isActive(true)) { $this->addWord('active', $class); } $page->setClass($class); $html = parent::renderDropdown($page, $renderIcons, $activeIconInverse, $options); return $html; }
/** * Returns whether page should be considered active or not * * This method will compare the page properties against the request object * that is found in the front controller. * * @param bool $recursive [optional] whether page should be considered * active if any child pages are active. Default is * false. * * @return bool whether page should be considered active or not */ public function isActive($recursive = false) { if (!$this->active) { $front = FrontController::getInstance(); $reqParams = $front->getRequest()->getParams(); if (!array_key_exists('module', $reqParams)) { $reqParams['module'] = $front->getDefaultModule(); } $myParams = $this->params; if (null !== $this->module) { $myParams['module'] = $this->module; } else { $myParams['module'] = $front->getDefaultModule(); } if (null !== $this->controller) { $myParams['controller'] = $this->controller; } else { $myParams['controller'] = $front->getDefaultControllerName(); } if (null !== $this->action) { $myParams['action'] = $this->action; } else { $myParams['action'] = $front->getDefaultAction(); } if (count(array_intersect_assoc($reqParams, $myParams)) == count($myParams)) { $this->active = true; return true; } } return parent::isActive($recursive); }
protected function htmlifyIcon(\Zend\Navigation\Page\AbstractPage $item, $activeIconInverse = true) { if ($item->icon) { $iClass = $item->icon; if ($activeIconInverse && $item->isActive(true)) { $classes = explode(' ', $iClass); $iconWhiteClassKey = array_search('icon-white', $classes); if ($iconWhiteClassKey === false) { //icon-white class not found $iClass .= ' icon-white'; } else { //icon-white class found unset($classes[$iconWhiteClassKey]); $iClass = implode(' ', $classes); } } $icon = '<i class="' . $iClass . '"></i> '; } else { $icon = ''; } return $icon; }