Created
June 24, 2011 18:58
-
-
Save lsolesen/1045424 to your computer and use it in GitHub Desktop.
Change tabs to contextual links in Drupal 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_menu_local_task() | |
* | |
* @param array $variables | |
* | |
* return string with html | |
*/ | |
function mytheme_menu_local_task($variables) { | |
$link = $variables['element']['#link']; | |
// remove the view link when viewing the node | |
if ($link['path'] == 'node/%/view') return false; | |
$link['localized_options']['html'] = TRUE; | |
return '<li>'.l($link['title'], $link['href'], $link['localized_options']).'</li>'."\n"; | |
} | |
/** | |
* Implements hook_menu_local_task() | |
* | |
* @param array $variables | |
* | |
* return string with html | |
*/ | |
function mytheme_menu_local_tasks(&$variables) { | |
$output = ''; | |
$has_access = user_access('access contextual links'); | |
if (!empty($variables['primary'])) { | |
$variables['primary']['#prefix'] = '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>'; | |
// Only display contextual links if the user has the correct permissions enabled. | |
// Otherwise, the default primary tabs will be used. | |
$variables['primary']['#prefix'] = ($has_access) ? | |
'<div class="contextual-links-wrapper"><ul class="contextual-links">' : '<ul class="tabs primary">'; | |
$variables['primary']['#suffix'] = ($has_access) ? | |
'</ul></div>' : '</ul>'; | |
$output .= drupal_render($variables['primary']); | |
} | |
if (!empty($variables['secondary'])) { | |
$variables['secondary']['#prefix'] = '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>'; | |
$variables['secondary']['#prefix'] = '<ul class="tabs secondary clearfix">'; | |
$variables['secondary']['#suffix'] = '</ul>'; | |
$output .= drupal_render($variables['secondary']); | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This solution does not work if views is active. Can you fix it or do i something wrong? I placed the code in the template.php file an add a
Please help!
Thanks.