Issues

ZF-8317: Zend_View_Helper_Navigation_Menu renderSiblings()

Description

At the moment Zend_View_Helper_Navigation_Menu view has some shortcomings.

First of all, if you want to only render active branch, with setRenderParents(true), you can't render eg. ->minDepth(1), if the last active depth is 0; it won't find the corresponding branch to be active. This was fixed for _renderDeepestMenu couple of versions ago, but the problem still persists for _renderMenu:


if ($found = $this->findActive($container, $minDepth, $maxDepth)) {

The $minDepth should be $minDepth - 1 for this line, like it is in _renderDeepestMenu.

Aside from this minor bug, there's also another shortcoming with the view helper. Namely you can't render a menu such that the siblings of the active branch are also rendered. Right now you can only render the siblings of the deepest active branch.

For an example of such menu, take a look here: http://mil.fi/rauhanturvaaja/perustiedot/… It prints the active branch, but also all siblings of its parents.

I've added a new method to the view helper, called renderSiblings() (default by false to keep things backward compatible), that lets you do just this.

I know there's a similar suggestion posted here earlier (http://www.zendframework.com/issues/browse/ZF-6941), but there are some problems with it:

  • It only checks the siblings of the deepest active branch's parent, this won't work if you render more than two depths of menu.
  • I think the name "expandBranch" is misleading and unclear. We already have renderParents(), so I think renderSiblings() is the appropriate name for this.

Included is the patch with the changes in the view helper, unit tests and documentation. Hopefully you'll consider adding it!

Comments

Any updates on this?

I think, you can use:


$view->navigation()->menu()->setOnlyActiveBranch()->setExpandSiblingNodesOfActiveBranch();