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
- // this is the template.php file!!
- // ....
- /**
- * @see http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_link/7
- */
- function YOURTHEMENAME_link($variables) {
- // in this example, I let "contact" and "node/9" links only be visible if the user is on these pages
- // and I let some other paths to be displayed at, see below...
- $your_paths_to_hide_array = array('contact', 'node/9'); // SUBSTITUTE IT with yours - empty cache every time you change that
- // these links will be visible only on their own pages -
- // but here you can define other paths where they can be visible at
- // if you don't want any other pages for these to be visible at, then
- // leave it empty (like this: array()),
- $link_also_visible_on_paths = array('node/3', 'any_other_path'); // SUBSTITUTE IT with your paths! - empty cache every time you change that
- $is_link_to_hide = in_array($variables['path'], $your_paths_to_hide_array);
- if ($is_link_to_hide) {
- $is_current_page_self = ($variables['path'] == $_GET['q']);
- $element_can_be_visible = $is_current_page_self || (!empty($link_also_visible_on_paths) && in_array($_GET['q'], $link_also_visible_on_paths));
- if (!$element_can_be_visible) {
- return '';
- }
- }
- 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>';
- }
- // ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement