Index: library/Zend/View/Helper/Navigation/Menu.php
===================================================================
--- library/Zend/View/Helper/Navigation/Menu.php (revision 24549)
+++ library/Zend/View/Helper/Navigation/Menu.php (working copy)
@@ -66,6 +66,11 @@
protected $_partial = null;
/**
+ * Expand all sibling nodes of active branch nodes
+ */
+ protected $_expandSiblingNodesOfActiveBranch = false;
+
+ /**
* View helper entry point:
* Retrieves helper and optionally sets container to operate on
*
@@ -135,8 +140,34 @@
{
return $this->_onlyActiveBranch;
}
+
+ /**
+ * Sets a flag indicating whether to expand all sibling nodes of the active branch
+ *
+ * @param bool $flag [optional] expand all siblings of
+ * nodes in the active branch. Default is true.
+ * @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
+ */
+ public function setExpandSiblingNodesOfActiveBranch($flag = true)
+ {
+ $this->_expandSiblingNodesOfActiveBranch = (bool) $flag;
+ return $this;
+ }
/**
+ * Returns a flag indicating whether to expand all sibling nodes of the active branch
+ *
+ * By default, this value is false, meaning the entire menu will be
+ * be rendered.
+ *
+ * @return bool whether siblings of nodes in the active branch should be expanded
+ */
+ public function getExpandSiblingNodesOfActiveBranch()
+ {
+ return $this->_expandSiblingNodesOfActiveBranch;
+ }
+
+ /**
* Enables/disables rendering of parents when only rendering active branch
*
* See {@link setOnlyActiveBranch()} for more information.
@@ -257,7 +288,7 @@
} else {
$options['indent'] = $this->getIndent();
}
-
+
if (isset($options['ulClass']) && $options['ulClass'] !== null) {
$options['ulClass'] = (string) $options['ulClass'];
} else {
@@ -287,6 +318,10 @@
if (!isset($options['onlyActiveBranch'])) {
$options['onlyActiveBranch'] = $this->getOnlyActiveBranch();
}
+
+ if (!isset($options['expandSiblingNodesOfActiveBranch'])) {
+ $options['expandSiblingNodesOfActiveBranch'] = $this->getExpandSiblingNodesOfActiveBranch();
+ }
if (!isset($options['renderParents'])) {
$options['renderParents'] = $this->getRenderParents();
@@ -359,6 +394,7 @@
* @param int|null $minDepth minimum depth
* @param int|null $maxDepth maximum depth
* @param bool $onlyActive render only active branch?
+ * @param bool $expandSibs render siblings of active branch nodes?
* @return string
*/
protected function _renderMenu(Zend_Navigation_Container $container,
@@ -366,7 +402,8 @@
$indent,
$minDepth,
$maxDepth,
- $onlyActive)
+ $onlyActive,
+ $expandSibs)
{
$html = '';
@@ -393,6 +430,21 @@
if ($depth < $minDepth || !$this->accept($page)) {
// 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
+ $accept = false;
+ if ($foundPage) {
+ if ($foundPage->hasPage($page)) {
+ // accept if page is a direct child of the active page
+ $accept = true;
+ } else if ($page->getParent()->isActive(true)) {
+ // page is a sibling of the active branch...
+ $accept = true;
+ }
+ }
+ if (!$isActive && !$accept) {
+ continue;
+ }
} else if ($onlyActive && !$isActive) {
// page is not active itself, but might be in the active branch
$accept = false;
@@ -503,7 +555,8 @@
$options['indent'],
$options['minDepth'],
$options['maxDepth'],
- $options['onlyActiveBranch']);
+ $options['onlyActiveBranch'],
+ $options['expandSiblingNodesOfActiveBranch']);
}
return $html;
Index: tests/Zend/View/Helper/Navigation/MenuTest.php
===================================================================
--- tests/Zend/View/Helper/Navigation/MenuTest.php (revision 24549)
+++ tests/Zend/View/Helper/Navigation/MenuTest.php (working copy)
@@ -540,4 +540,30 @@
$this->assertEquals($expected, $this->_helper->render($this->_nav3));
}
+
+ /**
+ * @group ZF-6941
+ */
+ public function testExpandSiblingNodesOfActiveBranch()
+ {
+ $this->_helper->setExpandSiblingNodesOfActiveBranch(true);
+
+ $expected = $this->_getExpected('menu/expandbranch.html');
+ $actual = $this->_helper->renderMenu();
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @group ZF-6941
+ */
+ public function testExpandSiblingNodesOfActiveBranchWhenShowingOnlyActiveBranch()
+ {
+ $this->_helper->setExpandSiblingNodesOfActiveBranch(true)->setOnlyActiveBranch(true);
+
+ $expected = $this->_getExpected('menu/expandbranch_onlyactivebranch.html');
+ $actual = $this->_helper->renderMenu();
+
+ $this->assertEquals($expected, $actual);
+ }
}
Index: documentation/manual/en/module_specs/Zend_View-Helpers-Navigation.xml
===================================================================
--- documentation/manual/en/module_specs/Zend_View-Helpers-Navigation.xml (revision 24549)
+++ documentation/manual/en/module_specs/Zend_View-Helpers-Navigation.xml (working copy)
@@ -1254,6 +1254,14 @@
should be rendered.
+
+
+
+ {get|set}ExpandSiblingNodesOfActiveBranch()
+ gets/sets a flag specifying whether the sibling nodes of all
+ nodes in the active branch should also be expanded and rendered.
+
+
@@ -1357,6 +1365,15 @@
+ expandSiblingNodesOfActiveBranch;
+ whether the sibling nodes of nodes in the active
+ branch should be expanded and rendered. Expects
+ a Boolean value.
+
+
+
+
+
renderParents; whether parents
should be rendered if only rendering active
branch. Expects a Boolean value.
@@ -1791,7 +1808,7 @@
]]>
-
+
+
+
Index: tests/Zend/View/Helper/Navigation/_files/expected/menu/expandbranch_onlyactivebranch.html
===================================================================
--- tests/Zend/View/Helper/Navigation/_files/expected/menu/expandbranch_onlyactivebranch.html (revision 0)
+++ tests/Zend/View/Helper/Navigation/_files/expected/menu/expandbranch_onlyactivebranch.html (revision 0)
@@ -0,0 +1,40 @@
+
\ No newline at end of file
Index: tests/Zend/View/Helper/Navigation/_files/expected/menu/expandbranch.html
===================================================================
--- tests/Zend/View/Helper/Navigation/_files/expected/menu/expandbranch.html (revision 0)
+++ tests/Zend/View/Helper/Navigation/_files/expected/menu/expandbranch.html (revision 0)
@@ -0,0 +1,52 @@
+
\ No newline at end of file