Closed (fixed)
Project:
Drupal core
Version:
6.x-dev
Component:
menu system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
22 Apr 2008 at 02:06 UTC
Updated:
8 Jun 2012 at 00:01 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
catchsubscribing.
Comment #2
catchTiny patch, works well. I think it's fine to have the same class as it does when a menu is in a block, ids are fine if someone needs to differentiate, and one day these might be themed blocks rather than special cases anyway.
Comment #3
dries commentedI've committed this to CVS HEAD. I leave it up to Gabor to decide whether this should be backported to Drupal 6.
Comment #4
pwolanin commentedThanks - I think this should be in 6.x too. I.e. it's really a bug.
Comment #5
drewish commentedseems like a bug to me... i couldn't figure out why the menu weren't activating. patch applies to DRUPAL-6 with a little fuzz but works correctly.
Comment #6
gábor hojtsyThanks, committed to Drupal 6 as well.
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #8
nikolai fischer commentedA german videotutorial shows how to fix the problem:
http://kommune3.org/tutorials/drupal-6/fehlende-active-trail-klasse-im-p...
---
Kommune3 Media
www.kommune3.org
Comment #9
buntstich commentedAt this time, i dont know how the Unix Terminal work. It is possible to post the new "menu.inc" for Drupal 6.2?
buntstich
Comment #10
buntstich commentedi add the Patch witdh a editor - the new file includes/menu.inc you will find in the attachment. You have also add these class in your theme stylesheet:
#navigation-primary ul.primary-links li a.active-trail {
background-color:# example;
background-repeat: example;
color:# example;
}
buntstich
Comment #11
scottatdrake commentedThis patch only assigns the class "active-trail" to the <a> tag. It should assign it to the parent <li> as well. This is how the "active" class is handled.Strike that. It does appear to apply the "active-trail" class to the parent <li>. In my case, however, it's only showing up in the <a> tag.
<li class="menu-127"><a href="/taxonomy/vocabulary/1" class="active-trail">Research</a></li>Can anyone offer thoughts as to why this might be happening?
Comment #12
damien tournoud commentedHum. I agree with scottatdrake on that one. The use of 'active-trail' is inconsistent:
<li>tag bytheme_menu_item()<a>tag bymenu_navigation_links()Is it inconsistent twice: both on the tag used and on the type of function that add the class (a theme function vs. a normal function).
Comment #13
damien tournoud commentedComment #14
sociotech commentedHere is a patch to the theme_links() function in theme.inc that adds the "active-trail" class to an enclosing
<li>element if the enclosed<a>link has it. It appends the following code right after the "active" class test:Of course, you could just use this patch in an override of the theme_links() function in your template.php file. But this seems like a generally useful feature, especially for themers trying to create advanced primary menu effects, so I'm submitting it for consideration in HEAD.
I'm not sure if the theme layer is the right place to address this issue (rather than, for example, in menu), but it's the place where the active class gets set for the
<li>element, so it seems reasonable.I've tested the patch but would appreciate feedback on anything I might be missing.
Comment #15
pwolanin commentedwe should be able to handle it better than this.
Ah! After re-reading the code, I see the original patch was flawed indeed. We need to add this to the array key to get the class onto the li tag rather than the a tag.
Comment #16
sociotech commentedNice! I suspected that there was a more fundamental level at which to apply the active-trail class to
<li>. Definitely a cleaner solution than my hack. Consider my patch withdrawn in favor of doing it in menu.inc instead.Any chance of this going into 6.6, rather than waiting for 7? In the meantime, I can continue to use my hack to theme_links() until it shows up in core.
Thanks.
Comment #17
pwolanin commentedSince we backported the original fix to 6.x, I certainly hope Gabor would take this improvment to that fix.
Comment #18
sociotech commentedI tested the above active-trail-li-249571-15.patch against one of our themes under Drupal 6.5 and it appears to work as advertised (and desired!). It indeed puts the active-trail class on the
<li>instead of the<a>tag. In my testing it gets a thumbs up.Comment #19
pwolanin commentedI think we can make the code even more concise - this is functionally the same, but one less LOC, and renames the variable used from $key to $class.
Comment #20
sociotech commentedJust tested it again and I agree. Cleaner, clearer, and it still works. Looks
goodbetter.Comment #21
pwolanin commentedok, then I think this is RTBC.
Comment #22
Anonymous (not verified) commentedI think I'm having problems with this in 6.x. My active trail is intermittent (works for some primary links, but not others). Can someone help me out with patching up 6.x menu.inc?
Comment #23
webchickI just love patches that remove convoluted logic whilst fixing bugs. Yay!
Committed to HEAD. Marking back to 6.x for consideration.
Comment #24
sociotech commentedWhile I'm very eager for this to get committed to 6.x, there is one area of potential breakage: if a theme has some effect based on the active-trail class on the
<a>element, then that effect will be broken.This is because the patch moves the active-trail class to the
<li>element, which is where it should be.So if a theme has, for example, a background image set for #primary-menu ul li a.active-trail, then it'll break unless it's changed to #primary-menu ul li.active-trail a.
One way around this would be to leave the active-trail class on the
<a>element as well, but that's not good markup practice (i.e., redundant class naming rather than relying on class inheritance).I guess I'd prefer to see the patch go through as it currently stands, because it's best practice, it's fixing a bug and Drupal shouldn't have to worry about breaking workarounds for bugs, which is what designing for active-trail on the
<a>element is.But I can't speak for others and I'm not sure what the general exposure would be on this. Our (TNT's) current exposure is about 4 themes out of a couple dozen.
Comment #25
Roy commentedThe patches do not work with Views and not with Path-auto on D6.5.
Comment #26
pwolanin commented@sociotech - if you are already tageting the a tags, maybe you can cover both possibilities in the theme?
li a.active-trail, li.active-trail a {}While I agree there is some impact on contrib themes, I don't think any of the core themes would be impacted, and having the class correctly placed should make better theming possible going forward.
Comment #27
sociotech commented@pwolanin - yeah, it's not a problem for us. We have a number of options going forward. Just wasn't sure about other folks' themes.
Comment #28
Anonymous (not verified) commentedI recently had an observation pertaining to the
<li>active-trail stuff. I don't know if this pertains to the same bug in this thread, and I'm sorry if it doesn't. I had some primary links (in 6.x) that would get assigned the active-trail class and others that wouldn't, but I couldn't figure out why, especially being new to drupal. Patching menu.inc and theme.inc didn't seem to help. It turned out that nodes with a relative path (in primary links) got assigned active-trail, while those where I'd typed in the URL and full path did not. It seems to behave the same, with and without the patch. Unless I'm incorrect, maybe it's worth verifying this in the patches? Bottomline = on my 6.x install, I don't get active-trail (or active in<a>) if I put the full path in the primary links.Comment #29
catchIf you put the full path in, it's treated as an external link, and Drupal won't know to apply the class to the
<li>. That'd be a different issue to this patch, and probably 'by design'.Comment #30
gábor hojtsyHuh, hah. I am not sure changing the $links keys are a great idea at this point. I expect themes might be hung on those keys to theme menu items specifically. I've at least seen themes which were applying special styles tied to the specific menu items. Adding a class in there would quickly break those themes (plus moving around the class is just a possible problem for these kinds of themes). Would be great to have feedback from others as well. We've heard that several of TNT's themes are affected.
Comment #31
pwolanin commented@Gabor - the TnT themes are affected, but as above they agree this is the correct fix.
Comment #32
catchI think it'd be worth adding a note in the release notes and/or maintainer news about the change. But this is enough of an annoyance that we really ought to fix it. The other option would be keeping .active on both the
<li>and<a>but I imagine we'd get even more complaints if we did that.Comment #33
drewish commentedI'm all for getting this into D6. It'd let me pull some nasty cruft out of my theme. It'd be nice if this was done as part of a non-security release so that people could update when it was convenient rather than in a rush to get the security fixes in.
Comment #34
gábor hojtsyI've talked through this with Peter again. He looked into the contrib repo and identified that our contrib themes are not affected. With all the support of the people here, I am leaning towards committing the patch. It does not apply to Drupal 6 however.
Comment #35
pwolanin commentedre-rolled for 6.x
Comment #36
gábor hojtsyThere was one 7.x artifact in it, concatenation spacing. I've fixed that and committed this one.
Comment #37
ParticleFizix commentedI agree that the methods described above are slightly cleaner, requiring only one class, but this would be slightly inconsistent with the block menus and the way the links in the headers "almost" work...
In order to have zero or little impact on existing themes, maybe maybe the LI class should be "active" and the "active-trail" class should remain on the links. This potentially should have zero or little impact on existing themes, because this method partially exists.
For example, in the current Drupal 6.4 release, I have a first level of primary links in the header styled as tabs, and primary links in the left block menu with access to all sub-levels.
I know people have gone over the problem, but it's just to accurately illustrate my example...
When I click on a header tab link or the equivalent top-Level link in the left hand block menu, the following is applied in the html...
However, when I click on a Sub-level link on the left hand side (block) menu, I get this...
The "active" class disappears from the LI item at the tabs at the header (but in a more consistent manner an "active-trail" class remains at the top in the block menu LI). If the "active" class was simply to remain on the LI top level list item, then all issues would surely be resolved.
Alternative would be to replicate the structure of the block menu and applying the same "active-trail" class to the LI and the link, but "nesting" class-names on different presentational/functional elements in this case can lead to bloated CSS styling, something we should try to avoid doing twice.
It's only a thought, and perhaps I've got the wrong end of the stick on the exact issue people are discussing. So don't shoot me in flames just "yet". With things being committed, I'm probably too late now anyway. :D
Comment #38
-Anti- commented> So if a theme has, for example, a background image set for
> #primary-menu ul li a.active-trail, then it'll break unless it's
> changed to #primary-menu ul li.active-trail a.
Thank you for telling me how to fix my menu, after you guys broke it!
Erm, I mean fixed it. Uh... I don't know what I mean! :)
Very thoughtful!
Keep up the good work.
Comment #39
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #40
David Stosik commentedHello,
I am still having this issue in Drupal 6.6. I have a book and a link to one of it's pages in Primary Links, and it doesn't get "active-trail" class whene I am navigating inside it, whereas the active-trail class is applied to the correct links inside book navigation block...
Oh, and I'm using a Zen subtheme.
Thanks for your help,
David
Comment #41
caktux commentedThis is still happening when on an active sub-page, primary links don't get the active class and $primary_links don't carry it either. This issue is also a duplicate of http://drupal.org/node/202245 which seems like it was forgotten for D6. Menu trails issues could also be related to this.
Comment #42
caktux commentedComment #43
drewish commentedhummm... well your patch would apply to HEAD still so i've included that as well as a properly re-rolled D6 patch but I haven't tested either.
Comment #44
pwolanin commentedFirst patch file is empty.
I'm not sure I understand the supposed bug here. Please clarify. For consistency, the class is added to the li, rather than the a tag.
see: http://api.drupal.org/api/function/theme_links/6
Comment #45
pwolanin commentedI see the class applied fine to the li in Primary links in my local D6 install using the Garland theme - so I as above, please explain the bug or check that this is not a custom theme-specific issue.
Comment #46
caktux commentedIndeed, this issue happens when theming, however shouldn't the link carry the in_active_trail info also? It doesn't change anything, simply passing the flag along (in its trail). It simply allows more flexibility in a one liner. Could modules also be looking for this in_active_trail flag?
Comment #47
pwolanin commentedsounds like a feature request then?
Comment #48
robodoc commentedHi,
I asked my provider to patch my drupal 6.12 with this:
Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.268
diff -u -p -r1.268 menu.inc
--- includes/menu.inc 14 Apr 2008 17:48:33 -0000 1.268
+++ includes/menu.inc 22 Apr 2008 02:00:25 -0000
@@ -1257,6 +1257,9 @@ function menu_navigation_links($menu_nam
$l = $item['link']['localized_options'];
$l['href'] = $item['link']['href'];
$l['title'] = $item['link']['title'];
+ if ($item['link']['in_active_trail']) {
+ $l['attributes'] = array('class' => 'active-trail');
+ }
// Keyed with unique menu id to generate classes from theme_links().
$links['menu-' . $item['link']['mlid']] = $l;
}
He received:
patching file menu.inc
Hunk #1 FAILED at 1257.
Any suggestions?
Thanks a lot in advance,
Marko
Comment #49
sun.core commentedProper status. Though I'm not sure about the proper status. Maybe you should create a new issue.
Comment #50
PinkChocobo commentedI think there are two issues, one is that in early drupal 6 and earlier releases, or in certain themes, the li does not include the "active-trail" class. The other is that on later versions where the li class is correct, the a does not include the "active" class. My simple CSS solution below applies only to the second one. Here is what I posted on a different thread:
I'm not sure exactly where to post what worked for me since there are so many threads open on this one subject, but this works for me in D6 using Barlow theme. I'm using the Primary Menu as parent menu and the secondary menu as the children of each separate link (secondary links set to primary links)
ie)
[link1] link2 link3
childoflink1 childoflink1 childoflink1
link1 [link2] link3
childoflink2 childoflink2 childoflink2 childoflink2
I used this in my stylesheet
.links a.active:visited, .links .active-trail a{
color:#990000;
text-decoration:none;
}
When I looked at the HTML source, the li had the correct active-trail class set, but the a did not include the active class and therefore was not working properly. If you do not have the li active-trail class, it could be because I installed the "Menu Trails" Module http://drupalmodules.com/module/menu-trails.
(I included the a.active:visited because the first link of the secondary child menu worked and the selected primary menu parent link included the active class as it should, it was just the rest of the child links that when clicked on, the parent link lost the the active class.)
This can be considered a work around, it's not really a good solution. Hope this helps at least as a temporary solution, I don't have the skill or the time to change the php to say if li class="active-trail", then a class="active".
Comment #51
sunI think we can and should just do this.
Comment #52
sunPart of #907690: Breadcrumbs don't work for dynamic paths & local tasks #2
Comment #54
rajesh.sharma1 commentedI have created SecondaryLink and I want when user will hit on that
that menu will be selected can any one help me
Comment #55
sunReverting status.