ZF-9524: Zend_View_Helper_Navigation_Menu setOnlyActiveBranch() renders whole tree when no sub pages

Issue Type: Improvement Created: 2010-03-23T16:30:50.000+0000 Last Updated: 2013-01-22T10:26:10.000+0000 Status: Closed Fix version(s): Reporter: Simon Corless (sico) Assignee: Frank Br├╝ckner (frosch) Tags: - Zend_Navigation

Related issues: - ZF-8773



** Edit: After thinking about it this should be a feature and is not a bug (or it is a bug but the opposite method should still be supported!).

Sometimes it may be desirable to show the items at the same level as the active node. **

The navigation menu view helper, when using the setOnlyActiveBranch() option will return the whole tree when the active branch doesn't contain any sub pages below the root / minimum depth.

In other words if a root element (or an element at minimum depth) doesn't have any sub pages the menu helper assumes the found active node is on the same depth as the minimum depth of the menu. This causes all elements in the same depth as the active element to be returned as part of the branch.

I would expect only the 'parent' element, in this case the first and last (only) element in the branch to be returned. It works fine when you are +1 levels deeper than the minimum depth.

I propose the following 'fix', or if this is not a bug then it should be a flag:

Line 404/405 should have the following condition added "&& $minDepth < $foundDepth":

<pre class="highlight">
if ((!$foundPage->hasPages() ||
 (is_int($maxDepth) && $foundDepth + 1 > $maxDepth)) && $minDepth < $foundDepth) {

Instead of:

<pre class="highlight">
if (!$foundPage->hasPages() ||
 is_int($maxDepth) && $foundDepth + 1 > $maxDepth) {

Therefore to accept a found page as part of the active branch it must not be on the same level as the minimum depth.


No comments to display

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.