SHOW:
|
|
- or go back to the newest paste.
| 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 | - | $your_path_to_hide = 'contact'; // SUBSTITUTE IT with yours (when using nodes, use it like this: 'node/9', etc.!) |
| 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 | - | $element_can_be_visible_on_node_id = 9; // SUBSTITUTE IT with your node's id!! |
| 12 | + | |
| 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 | } |