Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Answer for question on Drupal Stack Exchange:
- // http://drupal.stackexchange.com/questions/27907/enable-a-nodes-menu-item-when-on-that-node
- /**
- * @see http://api.drupal.org/api/drupal/includes%21menu.inc/function/theme_menu_link/7
- */
- function YOURTHEMENAME_menu_link(array $variables) {
- $your_path_to_hide = 'contact'; // SUBSTITUTE IT with yours (when using nodes, use it like this: 'node/9', etc.!)
- $is_element_to_hide = ($variables['element']['#href'] == $your_path_to_hide);
- if($is_element_to_hide){
- $element_can_be_visible_on_node_id = 9; // SUBSTITUTE IT with your node's id!!
- $element_can_be_visible = (arg(0)=='node' && arg(1) == $element_can_be_visible_on_node_id);
- if(!$element_can_be_visible){
- return '';
- }
- }
- $element = $variables['element'];
- $sub_menu = '';
- if ($element['#below']) {
- $sub_menu = drupal_render($element['#below']);
- }
- $output = l($element['#title'], $element['#href'], $element['#localized_options']);
- return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement