Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
}
....
}
Comment | File | Size | Author |
---|---|---|---|
#2 | admin_menu.span_.2.patch | 2.35 KB | sun |
#1 | Selection_027.png | 15.97 KB | Dave Reid |
Comments
Comment #1
Dave ReidScreenshot 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.
Comment #2
sunOK, how about this? Seems to work for me, but I didn't test extensively.
Comment #4
sun#2: admin_menu.span_.2.patch queued for re-testing.
Comment #5
sunThanks 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.