Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I have a case where nodes can be given more than one term. In this case I would like each menu item corresponding to each term to be marked as active.
Eg My terms are A,B,C and D. I have a menu with a link for each term. If I create a node and reference terms B and D, I would like the menu links for both B and D to have the 'active-trail' class.
Is this possible?
Thanks in advance.
Comments
Comment #1
Dmitriy.trt CreditAttribution: Dmitriy.trt commentedHi,
Unfortunately, it is impossible to "activate" multiple links at once on the same menu. It's a Drupal menu system limitation. But it is possible to activate one link per menu, so the only suggestion is to put term links in different menus and enable the "Separate active trail for each menu" option on Taxonomy Menu Trails configuration (on the node type settings). However, I'm not sure if this is suitable for your situation.
Comment #2
tripper54 CreditAttribution: tripper54 commentedThanks for the quick response. For others that might find this, I hacked my way around it by conditionally adding the 'active-trail' class to the link in a theme_preprocess_menu_link function.
Comment #4
studio-days CreditAttribution: studio-days commentedHi - just wondering if you could please provide more detailed info on your workaround. I'm needing the same fax.
cheers
Comment #5
tripper54 CreditAttribution: tripper54 commentedThis is roughly what I used in my theme's template.php. Braces nesting might be a bit wonky, but you'll get the idea :
Comment #6
ShaneOnABike CreditAttribution: ShaneOnABike commentedUnfortunately, this was auto-closed. :(
I can report this issue still exists actually and it seems that the only one trail is actually processed. I noticed that in the function
_taxonomy_menu_trails_fetch_link_deepest($vars)
there is some funky break conditions which I believe are doing the ejection before it needs to be :(Comment #7
ShaneOnABike CreditAttribution: ShaneOnABike commentedActually further coding and this isnt going to work due to the way that Drupal sets the menu items (only allowing one path to be active). Bummer but the code above is awesome. If you are using entity items you have to use target_id instead of tid :)