From #1899474: Show entire devel menu rather than just 'Variable editor' I found it impossible to create a text-only item in the admin menu like the following:

function custom_admin_menu_output_build(&$content) {
  $content['icon']['icon']['text-only'] = array(
    '#title' => t('This is a text only link.'),
  );
}

I found that to get it to render properly, I have to use the following which just seems wrong:

  $content['icon']['icon']['text-only'] = array(
    '#title' => t('This is a text only link.'),
    '#href' => '#',
    '#options' => array(
      'external' => TRUE,
    ),
  );

Also, by nature this item doesn't get wrapped in a span either, it's just text inside the li. I have a suspicion that theme_admin_menu_links() should wrap text-only in no matter what in order to be able to style it. The current code related to text-only links is:

function theme_admin_menu_links($variables) {
    ....
    // Handle plain text items, but do not interfere with menu additions.
    elseif (!isset($elements[$path]['#type']) && isset($elements[$path]['#title'])) {
      if (!empty($elements[$path]['#options']['html'])) {
        $title = $elements[$path]['#title'];
      }
      else {
        $title = check_plain($elements[$path]['#title']);
      }
      if (!empty($elements[$path]['#options']['attributes'])) {
        $link .= '<span' . drupal_attributes($elements[$path]['#options']['attributes']) . '>' . $title . '</span>';
      }
      else {
        $link .= $title;
      }
    }
    ....
}
CommentFileSizeAuthor
#2 admin_menu.span_.2.patch2.35 KBsun
#1 Selection_027.png15.97 KBDave Reid
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

FileSize
15.97 KB

Screenshot demonstrating what this currently looks like just using #title.

See #1899474: Show entire devel menu rather than just 'Variable editor' for how a text-only item looks when using the workaround.

sun’s picture

Status: Active » Needs review
FileSize
2.35 KB

OK, how about this? Seems to work for me, but I didn't test extensively.

Status: Needs review » Needs work

The last submitted patch, admin_menu.span_.2.patch, failed testing.

sun’s picture

Status: Needs work » Needs review

#2: admin_menu.span_.2.patch queued for re-testing.

sun’s picture

Title: Cannot add text-only items » Text-only items are not output correctly
Status: Needs review » Fixed

Thanks for reporting, reviewing, and testing! Committed to all branches.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.