Advertisement
Sk8erPeter

Enable a node's menu item when on that node? /2,if same path

Apr 9th, 2012
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Answer for question on Drupal Stack Exchange:
  2. // http://drupal.stackexchange.com/questions/27907/enable-a-nodes-menu-item-when-on-that-node
  3.  
  4. /**
  5.  * @see http://api.drupal.org/api/drupal/includes%21menu.inc/function/theme_menu_link/7
  6.  */
  7. function YOURTHEMENAME_menu_link(array $variables) {
  8.  
  9.   $element_can_be_visible_on_node_id = 9; // SUBSTITUTE IT with your node's id!!
  10.   $your_path_to_hide = 'node/'.$element_can_be_visible_on_node_id; // SUBSTITUTE IT with yours (when using nodes, use it like this: 'node/9', etc.!)
  11.   $is_element_to_hide = ($variables['element']['#href'] == $your_path_to_hide);
  12.   if($is_element_to_hide){
  13.     $element_can_be_visible = (arg(0)=='node' && arg(1) == $element_can_be_visible_on_node_id);
  14.    
  15.     if(!$element_can_be_visible){
  16.       return '';
  17.     }
  18.   }
  19.  
  20.   $element = $variables['element'];
  21.   $sub_menu = '';
  22.  
  23.   if ($element['#below']) {
  24.     $sub_menu = drupal_render($element['#below']);
  25.   }
  26.   $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  27.   return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement