When the active-trail is added in menu_navigation_links() any previously added attributes are lost.

On line 1317 of the current HEAD (rev 1.275) it looks like this:

if ($item['link']['in_active_trail']) {
        $l['attributes'] = array('class' => 'active-trail');
      }

As you can see the $l['attributes'] is just assigned without checking if it is already defined or not.

A possible fix is to change it to look like this:

      if ($item['link']['in_active_trail']) {
        // only initiate $l['attributes'] to an empty array if it doesn't already exist
        if (!isset($l['attributes'])) $l['attributes'] = array();

        // if $l['attributes']['class'] exists append ' active-trail'
        // and if it doesn't just assign 'active-trail'
        if (isset($l['attributes']['class'])) {
          $l['attributes']['class'] .= ' active-trail';	
        } 
        else { 
          $l['attributes']['class'] = 'active-trail'; 
        }
      }

Comments

Anonymous’s picture

Status: Active » Needs review
pwolanin’s picture

Status: Needs review » Postponed (maintainer needs more info)

no actual patch attached. see: http://drupal.org/patch

pwolanin’s picture

Version: 6.x-dev » 7.x-dev

FYI - that code was added in this recent issue: http://drupal.org/node/249571

So, I think we may be able to fix before 6.3 even. However, it should be fixed in 7.x first.
Maybe it could be coded more compactly:

      if ($item['link']['in_active_trail']) {
        if (empty($l['attributes']['class'])) {
          $l['attributes'] = array('class' => 'active-trail');
        }
        else {
          $l['attributes']['class'] .= ' active-trail';   
        }
      }
Anonymous’s picture

I just checked out drupal from cvs but I can't see those changes in there.

this is what I checked out:
cvs -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal checkout drupal

Did I checkout the wrong version?

pwolanin’s picture

that checkout should give you HEAD (7.x). Which changes were you looking for?

The above code is a little wrong. Should be more like:

      if ($item['link']['in_active_trail']) {
        if (empty($l['attributes'])) {
          $l['attributes'] = array('class' => 'active-trail');
        }
        else {
          $l['attributes']['class'] = empty($l['attributes']['class']) ? 'active-trail' : $l['attributes']['class'] . ' active-trail';  
        }
      }
Anonymous’s picture

I was looking for the changes mentioned here http://drupal.org/node/249571
According to the comments in the thread it looks like it was commited both to the 6 and 7 branches.

pwolanin’s picture

StatusFileSize
new899 bytes

The code is there in 7.x. line 1318 of menu.inc: $l['attributes'] = array('class' => 'active-trail');

Here's a patch for 7.x, also applies to 6.x with fuzz.

pwolanin’s picture

Status: Postponed (maintainer needs more info) » Needs review
chx’s picture

Status: Needs review » Reviewed & tested by the community

Nice and simple.

pwolanin’s picture

StatusFileSize
new913 bytes

here's a patch that applies with no fuzz to 6.x (exact same code).

pwolanin’s picture

patch still applies cleanly to 7.x

All tests pass with the patch, except for known failures (same with and without the patch):

Site-wide contact form: 120 passes, 4 fails, 0 exceptions
Core filters: 48 passes, 12 fails, 0 exceptions
Poll create: 27 passes, 7 fails, 0 exceptions
XML-RPC validator 0 passes, 0 fails, 3 exceptions

paul.lovvik’s picture

#10 patch applies cleanly to 6.3. Code looks good.

gábor hojtsy’s picture

OK, committed to 6.x and keeping RTBC for 7.x.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD for D7.x. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.