You are here

function special_menu_items_link in Special menu items 7

Same name and namespace in other branches
  1. 7.2 special_menu_items.module \special_menu_items_link()

Override of theme_link() This function will render link if it is "nolink" or "separator". Otherwise it will call originally overwritten menu_item_link function.

1 string reference to 'special_menu_items_link'
special_menu_items_theme_registry_alter in ./special_menu_items.module
Implementation of hook_theme_registry_alter() We replace theme_menu_item_link with our own function.

File

./special_menu_items.module, line 48
Module to enable placeholder or separator menu items.Placeholder is a menu item which is actually not a link. Something like this is useful with drop down menus where we want to have a parent link which is actually not linking to a page but which is…

Code

function special_menu_items_link(array $variables) {
  if (in_array($variables['path'], array(
    '<nolink>',
    '<separator>',
  ))) {
    switch ($variables['path']) {
      case '<nolink>':
        $tag = variable_get('special_menu_items_nolink_tag', '<span>');
        $title = $variables['options']['html'] ? $variables['text'] : check_plain($variables['text']);
        break;
      case '<separator>':
        $tag = variable_get('special_menu_items_separator_tag', '<span>');
        $title = variable_get('special_menu_items_separator_value', '<hr>');
        break;
    }
    $attributes = drupal_attributes($variables['options']['attributes']);
    if ($tag != '<a>') {

      // <a> tags can have these but a <span> cannot, so we remove them.
      foreach (array(
        'accesskey',
        'target',
        'rel',
        'name',
      ) as $attribute) {
        $attributes = preg_replace("/ {$attribute}=\".*\"/i", "", $attributes);
      }
    }
    return special_menu_items_render_menu_item($tag, $title, $attributes);
  }

  // Call the original theme function for normal menu link.
  return theme('special_menu_items_link_default', $variables);
}