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

Dmitriy.trt’s picture

Status: Active » Fixed

Hi,

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.

tripper54’s picture

Thanks 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.

Status: Fixed » Closed (fixed)

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

studio-days’s picture

Hi - just wondering if you could please provide more detailed info on your workaround. I'm needing the same fax.

cheers

tripper54’s picture

This is roughly what I used in my theme's template.php. Braces nesting might be a bit wonky, but you'll get the idea :

function MYTHEME_preprocess_menu_link(&$variables) {
// For the news sub-menu, nodes can be classified with multiple news categories.
  // If this is the case, each category must be given the 'active-trail' class.
  if (isset($variables['element']['#original_link']['menu_name']) &&
      ($variables['element']['#original_link']['menu_name'] == 'menu-news-sub-menu')) {
    //Check if the link is a term link
    $href = explode('/', $variables['element']['#href']);
    if ($href[0] == 'taxonomy') {
      $menu_current_tid = $href[2];
      if (($current_node = menu_get_object('node'))) {
        if (isset($current_node->field_article_category)) {
          foreach ($current_node->field_article_category['und'] as $node_term) {
            if ($node_term['tid'] == $menu_current_tid) {
              $variables['element']['#localized_options']['attributes']['class'][] = 'active-trail';
              $variables['element']['#attributes']['class'][] = 'active-trail';
            }
          }
        }
      }
    }
}
}
ShaneOnABike’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

Unfortunately, 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 :(

ShaneOnABike’s picture

Status: Active » Closed (works as designed)

Actually 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 :)