Advertisement
Sk8erPeter

Enable a node's menu item when on that node? /4,exact exampl

Apr 13th, 2012
170
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. // this is the template.php file!!
  5. // ....
  6.  
  7. /**
  8.  * @see http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_link/7
  9.  */
  10. function YOURTHEMENAME_link($variables) {
  11.     // in this example, I let "node/425" link only be visible if the user is on this page
  12.     $your_paths_to_hide_array = array('node/425'); // empty cache every time you change that
  13.     $link_also_visible_on_paths = array(); // empty cache every time you change that
  14.     $is_link_to_hide = in_array($variables['path'], $your_paths_to_hide_array);
  15.     if ($is_link_to_hide) {
  16.         $is_current_page_self = ($variables['path'] == $_GET['q']);
  17.         $element_can_be_visible = $is_current_page_self || (!empty($link_also_visible_on_paths) && in_array($_GET['q'], $link_also_visible_on_paths));
  18.  
  19.         if (!$element_can_be_visible) {
  20.             return '';
  21.         }
  22.     }
  23.     return '<a href="' . check_plain(url($variables['path'], $variables['options'])) . '"' . drupal_attributes($variables['options']['attributes']) . '>' . ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . '</a>';
  24. }
  25.  
  26. // ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement