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


** 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":

if ((!$foundPage->hasPages() ||
 (is_int($maxDepth) && $foundDepth + 1 > $maxDepth)) && $minDepth < $foundDepth) {

Instead of:

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