Index: library/Zend/View/Helper/Navigation/Menu.php
===================================================================
--- library/Zend/View/Helper/Navigation/Menu.php (revision 25013)
+++ library/Zend/View/Helper/Navigation/Menu.php (working copy)
@@ -74,8 +74,17 @@
/**
* Expand all sibling nodes of active branch nodes
+ *
+ * @var bool
*/
protected $_expandSiblingNodesOfActiveBranch = false;
+
+ /**
+ * Adds CSS class from page to li element
+ *
+ * @var bool
+ */
+ protected $_addPageClassToLi = false;
/**
* View helper entry point:
@@ -260,6 +269,46 @@
return $this->_partial;
}
+ /**
+ * Adds CSS class from page to li element
+ *
+ * Before:
+ *
+ *
+ *
+ * After:
+ *
+ *
+ *
+ * @param bool $flag [optional] adds CSS class from
+ * page to li element
+ *
+ * @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
+ */
+ public function addPageClassToLi($flag = true)
+ {
+ $this->_addPageClassToLi = (bool) $flag;
+
+ return $this;
+ }
+
+ /**
+ * Returns a flag indicating whether the CSS class from page to be added to
+ * li element
+ *
+ * @return bool
+ */
+ public function getAddPageClassToLi()
+ {
+ return $this->_addPageClassToLi;
+ }
+
// Public methods:
/**
@@ -291,9 +340,12 @@
$attribs = array(
'id' => $page->getId(),
'title' => $title,
- 'class' => $page->getClass()
);
+ if (false === $this->getAddPageClassToLi()) {
+ $attribs['class'] = $page->getClass();
+ }
+
// does page have a href?
if ($href = $page->getHref()) {
$element = 'a';
@@ -371,6 +423,10 @@
$options['renderParents'] = $this->getRenderParents();
}
+ if (!isset($options['addPageClassToLi'])) {
+ $options['addPageClassToLi'] = $this->getAddPageClassToLi();
+ }
+
return $options;
}
@@ -381,13 +437,14 @@
* 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
+ * @param bool $addPageClassToLi adds CSS class from
+ * page to li element
* @return string rendered menu
*/
protected function _renderDeepestMenu(Zend_Navigation_Container $container,
@@ -395,7 +452,8 @@
$indent,
$minDepth,
$maxDepth,
- $ulId)
+ $ulId,
+ $addPageClassToLi)
{
if (!$active = $this->findActive($container, $minDepth - 1, $maxDepth)) {
return '';
@@ -435,7 +493,19 @@
if (!$this->accept($subPage)) {
continue;
}
- $liClass = $subPage->isActive(true) ? ' class="active"' : '';
+
+ $liClass = '';
+ if ($subPage->isActive(true) && $addPageClassToLi) {
+ $liClass = $this->_htmlAttribs(
+ array('class' => 'active ' . $subPage->getClass())
+ );
+ } else if ($subPage->isActive(true)) {
+ $liClass = $this->_htmlAttribs(array('class' => 'active'));
+ } else if ($addPageClassToLi) {
+ $liClass = $this->_htmlAttribs(
+ array('class' => $subPage->getClass())
+ );
+ }
$html .= $indent . '