Home ›
Have menu local tasks (view, edit, etc. tabs) show menu item description as tooltipHave menu local tasks (view, edit, etc. tabs) show menu item description as tooltip
Submitted by Benjamin Melançon on May 4, 2012 - 12:43pm
Most menu items in Drupal 7 show a link tool-tip, or title, but local tasks (the tabs you are most used to seeing as the edit link tab on full node pages sadly do not follow this sensible pattern.
Until Drupal core is fixed so that menu item "description" is applied to title attribute of menu tab links", here is a fix for Drupal 7. Change this to your custom theme's name (replace 'example') and drop into your theme's template.php file:
<?php
/**
* Override theme_menu_local_task().
*
* @param array $variables
* @return string
*/
function example_menu_local_task($variables) {
$link = $variables['element']['#link'];
$link_text = $link['title'];
if (!empty(
$variables['element']['#active'])) {
// Add text to indicate active tab for non-visual users.
$active = '<span class="element-invisible">' . t('(active tab)') . '</span>';
// If the link does not contain HTML already, check_plain() it now.
// After we set 'html'=TRUE the link will not be sanitized by l().
if (empty($link['localized_options']['html'])) {
$link['title'] = check_plain($link['title']);
}
$link['localized_options']['html'] = TRUE;
$link_text = t('!local-task-title!active', array('!local-task-title' => $link['title'], '!active' => $active));
}
$link['localized_options']['attributes'] = array('title' => $link['description']);
return
'<li' . (!empty($variables['element']['#active']) ? ' class="active"' : '') . '>' . l($link_text, $link['href'], $link['localized_options']) . "</li>\n";
}
?>
The key line that has been added is:
<?php
$link['localized_options']['attributes'] = array('title' => $link['description']);
?>
Searched words:
drupal description title tooltip in local task tabs
Comments
Thanks for this. Alas, when
Thanks for this. Alas, when this was committed to Drupal 8, they added an unnecessary and incorrect check_plain. I reported the bug and noted that your proposed code was correct.
Post new comment