Highlight View parent menu item on node page and rebuild breadcrumb If you are new to Drupal, as I am, you surely asked yourself once about "How can I highlight parent Views menu item even if I am on a child node? And how can I keep a correct breadcrumb if I use one?"... That's why I wanted to share a little clue in here.

My situation:

I have a content-type named "Testimonial". I created a View for my testimonial's nodes, with a menu item "Témoignages" in a secondary menu on the left of my page (called "Ressources").

First problem: the menu

/!\ This menu displays only on the pages whose menu item is present in the menu. For example, "Marchés publics en Wallonie", "Aides publiques en Wallonie", "Témoignages" (= Testimonials), ...



When I am the the View page, with the list of my testimonial's nodes, the menu item is highlighted automatically by Drupal. Nice.

But when I click on a node and access the full view page, the "Ressources" menu disappears. This behaviour is normal for all other menu item's children pages. But I want to make an exception for the testimonials.

Second problem: the breadcrumb

Breadcrumb on Views page:



Breadcrumb on testimonials node page:



My final question:

How can I keep the menu block in testimonials node pages (only) and make the menu item "Témoignages" highlighted? And how can I keep a correct breadcrumb in the same time?
To display the "Ressources" menu in a testimonial node page, Drupal should believe that we are actually on the "Témoignages" Views page. Plus, it will highlight automatically the good menu item.

But, we also need a correct breadcrumb. That's why we have to save in a variable the "true nature of the page" (a node) before letting know to Drupal that we are on a view.

That's that we do here:

function pwe_testimonial_node_view($node, $view_mode, $langcode) {
  // When we are on a Testimonial node page
  if($node-&gt;type == "testimonial" &amp;&amp; $view_mode == "full") {
    // We save the true nature of the page
    $_SESSION['pwe_testimonial_active_trail'] = serialize(menu_get_active_trail());
    $_GET['pwe_node_id'] = $node-&gt;nid;
    // And set the active menu item as "Témoignages"
    menu_set_active_item("testimonial");
  } else {
    // If we are not on a Testimonial node page,
    // we unset the custom variable.
    if(isset($_SESSION['pwe_testimonial_active_trail'])) {
      unset($_SESSION['pwe_testimonial_active_trail']);
    }
  }
}


To rebuild the true breadcrumb, we use the variable saved in previous function.

function pwe_testimonial_menu_breadcrumb_alter(&amp;$active_trail, $item) {
  if($item &amp;&amp; $item['path'] == "testimonial") {
    if($_GET['pwe_node_id']) {
      if(isset($_SESSION['pwe_testimonial_active_trail'])) {
        unset($_SESSION['pwe_testimonial_active_trail']);
      }
    }
    if(isset($_SESSION['pwe_testimonial_active_trail'])) {
      $original_active_trail = unserialize($_SESSION['pwe_testimonial_active_trail']);
      if(is_array($original_active_trail)) {
        $total = count($active_trail);
        $active_trail[$total] = $item;
      }
    }
  }
}




That's all. I hope this little Q&amp;A sharing knowledge will help someone in the future.