User login

Have menu local tasks (view, edit, etc. tabs) show menu item description as tooltip

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

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.