Index: library/Zend/View/Helper/Navigation/Menu.php =================================================================== --- library/Zend/View/Helper/Navigation/Menu.php (revision 24692) +++ library/Zend/View/Helper/Navigation/Menu.php (working copy) @@ -45,6 +45,20 @@ protected $_ulClass = 'navigation'; /** + * CSS class to use for the parent li element + * + * @var string + */ + protected $_parentClass = 'parent'; + + /** + * Whether parent li elements should be rendered with parent class + * + * @var bool + */ + protected $_renderParentClass = false; + + /** * Whether only active branch should be rendered * * @var bool @@ -111,6 +125,55 @@ } /** + * Sets CSS class to use for the parent li elements when rendering + * + * @param string $parentClass CSS class to set to parents + * @return Zend_View_Helper_Navigation_Menu fluent interface, returns self + */ + public function setParentClass($parentClass) + { + if (is_string($parentClass)) { + $this->_parentClass = $parentClass; + } + + return $this; + } + + /** + * Returns CSS class to use for the parent lie elements when rendering + * + * @return string CSS class + */ + public function getParentClass() + { + return $this->_parentClass; + } + + /** + * Enables/disables rendering of parent class to the li element + * + * @param bool $flag [optional] render with parent + * class. Default is true. + * @return Zend_View_Helper_Navigation_Menu fluent interface, returns self + */ + public function setRenderParentClass($flag = true) + { + $this->_renderParentClass = (bool) $flag; + return $this; + } + + /** + * Returns flag indicating whether parent class should be rendered to the li + * element + * + * @return bool whether parent class should be rendered + */ + public function getRenderParentClass() + { + return $this->_renderParentClass; + } + + /** * Sets a flag indicating whether only active branch should be rendered * * @param bool $flag [optional] render only active @@ -264,6 +327,12 @@ $options['ulClass'] = $this->getUlClass(); } + if (isset($options['parentClass']) && $options['parentClass'] !== null) { + $options['parentClass'] = (string) $options['parentClass']; + } else { + $options['parentClass'] = $this->getParentClass(); + } + if (array_key_exists('minDepth', $options)) { if (null !== $options['minDepth']) { $options['minDepth'] = (int) $options['minDepth']; @@ -292,6 +361,10 @@ $options['renderParents'] = $this->getRenderParents(); } + if (!isset($options['renderParentClass'])) { + $options['renderParentClass'] = $this->getRenderParentClass(); + } + return $options; } @@ -359,6 +432,8 @@ * @param int|null $minDepth minimum depth * @param int|null $maxDepth maximum depth * @param bool $onlyActive render only active branch? + * @param string $parentClass CSS class for parent li's + * @param bool $renderParentClass Render parent class? * @return string */ protected function _renderMenu(Zend_Navigation_Container $container, @@ -366,7 +441,9 @@ $indent, $minDepth, $maxDepth, - $onlyActive) + $onlyActive, + $parentClass, + $renderParentClass) { $html = ''; @@ -443,7 +520,17 @@ } // render li tag and page - $liClass = $isActive ? ' class="active"' : ''; + $liClass = ''; + if ($isActive && $page->hasChildren() && $renderParentClass) { + // Check max depth + if ((is_int($maxDepth) && ($depth + 1 < $maxDepth)) || !is_int($maxDepth)) { + $liClass = sprintf(' class="active %s"', $parentClass); + } else { + $liClass = ' class="active"'; + } + } else if ($isActive) { + $liClass = ' class="active"'; + } $html .= $myIndent . ' ' . self::EOL . $myIndent . ' ' . $this->htmlify($page) . self::EOL; @@ -503,7 +590,9 @@ $options['indent'], $options['minDepth'], $options['maxDepth'], - $options['onlyActiveBranch']); + $options['onlyActiveBranch'], + $options['parentClass'], + $options['renderParentClass']); } return $html;