Index: library/Zend/View/Helper/Navigation/Menu.php =================================================================== --- library/Zend/View/Helper/Navigation/Menu.php (revision 24964) +++ library/Zend/View/Helper/Navigation/Menu.php (working copy) @@ -43,6 +43,13 @@ * @var string */ protected $_ulClass = 'navigation'; + + /** + * CSS class to use for the active elements + * + * @var string + */ + protected $_activeClass = 'active'; /** * Unique identifier (id) for the ul element @@ -121,6 +128,31 @@ { return $this->_ulClass; } + + /** + * Sets CSS class to use for the active elements when rendering + * + * @param string $activeClass CSS class to set + * @return Zend_View_Helper_Navigation_Menu fluent interface, returns self + */ + public function setActiveClass($activeClass) + { + if (is_string($activeClass)) { + $this->_activeClass = $activeClass; + } + + return $this; + } + + /** + * Returns CSS class to use for the active elements when rendering + * + * @return string CSS class + */ + public function getActiveClass() + { + return $this->_activeClass; + } /** * Sets unique identifier (id) to use for the first 'ul' element when @@ -320,24 +352,36 @@ */ protected function _normalizeOptions(array $options = array()) { + // Indent if (isset($options['indent'])) { $options['indent'] = $this->_getWhitespace($options['indent']); } else { $options['indent'] = $this->getIndent(); } - + + // Ul class if (isset($options['ulClass']) && $options['ulClass'] !== null) { $options['ulClass'] = (string) $options['ulClass']; } else { $options['ulClass'] = $this->getUlClass(); } + // Ul id if (isset($options['ulId']) && $options['ulId'] !== null) { $options['ulId'] = (string) $options['ulId']; } else { $options['ulId'] = $this->getUlId(); } + // Active class + if (isset($options['activeClass']) && $options['activeClass'] !== null + ) { + $options['activeClass'] = (string)$options['activeClass']; + } else { + $options['activeClass'] = $this->getActiveClass(); + } + + // Minimum depth if (array_key_exists('minDepth', $options)) { if (null !== $options['minDepth']) { $options['minDepth'] = (int) $options['minDepth']; @@ -359,14 +403,17 @@ $options['maxDepth'] = $this->getMaxDepth(); } + // Only active branch if (!isset($options['onlyActiveBranch'])) { $options['onlyActiveBranch'] = $this->getOnlyActiveBranch(); } - + + // Expand sibling nodes of active branch if (!isset($options['expandSiblingNodesOfActiveBranch'])) { $options['expandSiblingNodesOfActiveBranch'] = $this->getExpandSiblingNodesOfActiveBranch(); } + // Render parents if (!isset($options['renderParents'])) { $options['renderParents'] = $this->getRenderParents(); } @@ -380,22 +427,24 @@ * Renders the deepest active menu within [$minDepth, $maxDeth], (called * from {@link renderMenu()}) * - * @param Zend_Navigation_Container $container container to render - * @param array $active active page and depth - * @param string $ulClass CSS class for first UL - * @param string $indent initial indentation - * @param int|null $minDepth minimum depth - * @param int|null $maxDepth maximum depth - * @param string|null $ulId unique identifier (id) for - * first UL - * @return string rendered menu + * @param Zend_Navigation_Container $container container to render + * @param array $active active page and depth + * @param string $ulClass CSS class for first UL + * @param string $indent initial indentation + * @param int|null $minDepth minimum depth + * @param int|null $maxDepth maximum depth + * @param string|null $ulId unique identifier (id) for + * first UL + * @param string|null $activeClass CSS class for active element + * @return string rendered menu */ protected function _renderDeepestMenu(Zend_Navigation_Container $container, $ulClass, $indent, $minDepth, $maxDepth, - $ulId) + $ulId, + $activeClass) { if (!$active = $this->findActive($container, $minDepth - 1, $maxDepth)) { return ''; @@ -435,7 +484,12 @@ if (!$this->accept($subPage)) { continue; } - $liClass = $subPage->isActive(true) ? ' class="active"' : ''; + + $liClass = ''; + if ($subPage->isActive(true)) { + $liClass = $this->_htmlAttribs(array('class' => $activeClass)); + } + $html .= $indent . ' ' . self::EOL; $html .= $indent . ' ' . $this->htmlify($subPage) . self::EOL; $html .= $indent . ' ' . self::EOL; @@ -459,6 +513,7 @@ * branch nodes? * @param string|null $ulId unique identifier (id) for * first UL + * @param string|null $activeClass CSS class for active element * @return string */ protected function _renderMenu(Zend_Navigation_Container $container, @@ -468,7 +523,8 @@ $maxDepth, $onlyActive, $expandSibs, - $ulId) + $ulId, + $activeClass) { $html = ''; @@ -496,7 +552,7 @@ // page is below minDepth or not accepted by acl/visibilty continue; } else if ($expandSibs && $depth > $minDepth) { - // page is not active itself, but might be in the active branch + // page is not active itself, but might be in the active branch $accept = false; if ($foundPage) { if ($foundPage->hasPage($page)) { @@ -574,7 +630,11 @@ } // render li tag and page - $liClass = $isActive ? ' class="active"' : ''; + $liClass = ''; + if ($isActive) { + $liClass = $this->_htmlAttribs(array('class' => $activeClass)); + } + $html .= $myIndent . ' ' . self::EOL . $myIndent . ' ' . $this->htmlify($page) . self::EOL; @@ -628,7 +688,8 @@ $options['indent'], $options['minDepth'], $options['maxDepth'], - $options['ulId']); + $options['ulId'], + $options['activeClass']); } else { $html = $this->_renderMenu($container, $options['ulClass'], @@ -637,7 +698,8 @@ $options['maxDepth'], $options['onlyActiveBranch'], $options['expandSiblingNodesOfActiveBranch'], - $options['ulId']); + $options['ulId'], + $options['activeClass']); } return $html;