Skip to content

Instantly share code, notes, and snippets.

@kasperg
Created February 24, 2012 14:34
Show Gist options
  • Save kasperg/1901270 to your computer and use it in GitHub Desktop.
Save kasperg/1901270 to your computer and use it in GitHub Desktop.
Drupal menu nolink function
<?php
/**
* @file modulename.module
*/
/**
* Implements hook_menu()
*/
function modulename_menu() {
// Special item to use as path for menu items that shouldn't link.
$items['<nolink>'] = array(
'page callback' => 'drupal_not_found',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
?>
<?php
/**
* @file template.php
*/
/**
* Theme menu-links, with optional nolink items.
*/
function themename_menu_link(&$variables) {
$element = $variables['element'];
if (preg_match('{<nolink>}', $element['#href'])) {
}
$sub_menu = '';
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
if (preg_match('{<nolink>}', $element['#href'])) {
$title = strip_tags(l($element['#title'], $element['#href'], $element['#localized_options']));
$css = NULL;
// Set a class if the link is in the active trail.
if (!empty($element['#original_link']['in_active_trail'])) {
$css = 'active-trail';
}
$output = '<span>' . $title . '</span>;
$element['#attributes']['class'][] = 'nolink';
}
else {
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
}
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment