Index: documentation/manual/en/module_specs/Zend_View-Helpers-Navigation.xml
===================================================================
--- documentation/manual/en/module_specs/Zend_View-Helpers-Navigation.xml (revision 16084)
+++ documentation/manual/en/module_specs/Zend_View-Helpers-Navigation.xml (working copy)
@@ -1197,6 +1197,14 @@
+ {get|set}ExpandBranch() gets/sets a flag
+ specifying whether the first depth and expand the active branch. It's render
+ the same entries as the OnlyActiveBranch option but also render all sibling
+ entries of the active branch.
+
+
+
+
{get|set}RenderParents() gets/sets a flag
specifying whether parents should be rendered when only
rendering active branch of a container. If set to
@@ -1284,6 +1292,13 @@
+ expandBranch; whether the first
+ depth and expand the active branch. Expects
+ a Boolean value.
+
+
+
+
renderParents; whether parents
should be rendered if only rendering active
branch. Expects a Boolean value.
@@ -1450,7 +1465,8 @@
'minDepth' => null,
'maxDepth' => null,
'onlyActiveBranch' => true,
- 'renderParents' => false
+ 'renderParents' => false,
+ 'expandBranch' => false
)
@@ -1755,6 +1771,58 @@
Community
]]>
+
+
Index: library/Zend/View/Helper/Navigation/Menu.php
===================================================================
--- library/Zend/View/Helper/Navigation/Menu.php (revision 16084)
+++ library/Zend/View/Helper/Navigation/Menu.php (working copy)
@@ -51,6 +51,13 @@
protected $_onlyActiveBranch = false;
/**
+ * Whether the first depth and the active branch should be rendered
+ *
+ * @var bool
+ */
+ protected $_expandBranch = false;
+
+ /**
* Whether parents should be rendered when only rendering active branch
*
* @var bool
@@ -136,6 +143,32 @@
}
/**
+ * Sets a flag indicating whether the first depth and expand the active branch
+ *
+ * @param bool $flag [optional] render the first depth and the active branch
+ * . Default is true.
+ * @return Zend_View_Helper_Navigation_Menu fluent interface, returns self
+ */
+ public function setExpandBranch($flag = true)
+ {
+ $this->_expandBranch = (bool) $flag;
+ return $this;
+ }
+
+ /**
+ * Returns a flag indicating whether the first depth and the active branch should be rendered
+ *
+ * By default, this value is false, meaning the entire menu will be
+ * be rendered.
+ *
+ * @return bool whether only active branch should be rendered
+ */
+ public function getExpandBranch()
+ {
+ return $this->_expandBranch;
+ }
+
+ /**
* Enables/disables rendering of parents when only rendering active branch
*
* See {@link setOnlyActiveBranch()} for more information.
@@ -289,6 +322,10 @@
if (!isset($options['renderParents'])) {
$options['renderParents'] = $this->getRenderParents();
}
+
+ if (!isset($options['expandBranch'])) {
+ $options['expandBranch'] = $this->getExpandBranch();
+ }
return $options;
}
@@ -363,7 +400,8 @@
$indent,
$minDepth,
$maxDepth,
- $onlyActive)
+ $onlyActive,
+ $expandBranch)
{
$html = '';
@@ -390,6 +428,21 @@
if ($depth < $minDepth || !$this->accept($page)) {
// page is below minDepth or not accepted by acl/visibilty
continue;
+ } else if ($expandBranch && $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;
@@ -500,7 +553,8 @@
$options['indent'],
$options['minDepth'],
$options['maxDepth'],
- $options['onlyActiveBranch']);
+ $options['onlyActiveBranch'],
+ $options['expandBranch']);
}
return $html;
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
Property changes on: tests\Zend\View\Helper\Navigation\_files\expected\menu\expandbranch.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
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
Property changes on: tests\Zend\View\Helper\Navigation\_files\expected\menu\expandbranch_onlyactivebranch.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Index: tests/Zend/View/Helper/Navigation/MenuTest.php
===================================================================
--- tests/Zend/View/Helper/Navigation/MenuTest.php (revision 16084)
+++ tests/Zend/View/Helper/Navigation/MenuTest.php (working copy)
@@ -354,10 +517,26 @@
$this->assertEquals($expected, $actual);
}
+ public function testSetExpandBranch()
+ {
+ $this->_helper->setExpandBranch(true);
+ $expected = $this->_getExpected('menu/expandbranch.html');
+ $actual = $this->_helper->renderMenu();
+ $this->assertEquals($expected, $actual);
+ }
+
+ public function testSetExpandBranchAndOnlyActiveBranch()
+ {
+ $this->_helper->setExpandBranch(true)->setOnlyActiveBranch(true);
+ $expected = $this->_getExpected('menu/expandbranch_onlyactivebranch.html');
+ $actual = $this->_helper->renderMenu();
+ $this->assertEquals($expected, $actual);
+ }
+
@@ -487,4 +666,22 @@
$this->assertEquals($expected, $actual);
}
-}
\ No newline at end of file
+
+ public function testOptionExpandBranch()
+ {
+ $options = array(
+ 'expandBranch' => true
+ );
+
+ $expected = $this->_getExpected('menu/expandbranch.html');
+ $actual = $this->_helper->renderMenu(null, $options);
+
+ $this->assertEquals($expected, $actual);
+ }
+}
\ No newline at end of file