ZF-8951: Zend_Navigation View Helper Menu - allow different active classes for active parents

Issue Type: Improvement Created: 2010-01-27T07:17:00.000+0000 Last Updated: 2013-01-11T10:28:35.000+0000 Status: Resolved Fix version(s): - 1.12.2 (25/Feb/13)

Reporter: Kenneth Kufluk (kennethkufluk) Assignee: Frank Brückner (frosch) Tags: - Zend_Navigation

  • After1.12.0
  • FixForZF1.12.1
  • zf-crteam-priority
  • zf-crteam-review

Related issues: - ZF-7003

Attachments: - Menu.php.patch


Ideally my output navigation would look something like this:

<pre class="highlight"> 

    <a href="">First Level</a>

            <a href="">Second Level</a>

I would like to display active parents differently from the active leaf nodes. Since I cannot use CSS markup for I need a different class for the parent nodes. This is a common use-case for me.

I suggest an amend to the Zend/View/Helper/Navigation/Menu.php

<pre class="highlight">
258             // create li element for page
259             $liCss = $page->isActive($recursive)
260                    ? ' class="active"'
261                    : '';


<pre class="highlight">
258             // create li element for page
259             $liCss = $page->isActive($recursive)
260                    ? ' class="active"'
261                    : '';
new             // show active parent
new             if (!$recursive && !$page->isActive(false) && $page->isActive(true)) $liCss = ' class="active-parent"';

This will not change the current behaviour for users using setParentActive. Those not using it will get extra classes which will not affect display (unless they happen to be using that class name).

I think this is a very common use-case, so warrants inclusion in the library, rather than simply using a partial menu template.

I suspect my code could be expressed more elegantly. The option could be added as a new configuration parameter.


Posted by Kai Uwe (kaiuwe) on 2010-10-21T01:23:46.000+0000

??I need a different class for the parent nodes.?? I think that would be a BC break in HTML and CSS.

My suggestion:

<pre class="highlight">
class="active parent"

In CSS you can write:

<pre class="highlight">

Posted by Frank Brückner (frosch) on 2011-10-10T22:02:53.000+0000

I have found a simple solution. I will write some unit tests and the implementation which includes:

  • Two new properties $_parentClass and $_renderParentClass
  • Getter and setter for these properties (setParentClass(), getParentClass(), setRenderParentClass(), getRenderParentClass())
  • Update the methods renderMenu(), _renderMenu() and _normalizeOptions

Posted by Frank Brückner (frosch) on 2012-03-21T19:12:15.000+0000

Patch and unit tests added.

Posted by Rob Allen (rob) on 2012-11-07T21:00:11.000+0000

Patch fails to apply

Posted by Rob Allen (rob) on 2012-11-07T21:00:52.000+0000

I'm also a little concerned that adding a class will result in unexpected styling. Maybe name the new class something like zf-nav-parent ?

Posted by Frank Brückner (frosch) on 2012-11-08T17:09:11.000+0000

Or "menu-parent"?

Posted by Frank Brückner (frosch) on 2013-01-11T10:28:09.000+0000

Fixed on trunk (25214) and release-1.12 (25215)

Posted by Frank Brückner (frosch) on 2013-01-11T10:28:35.000+0000

Standard parent class is "menu-parent".

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.