You are here

function menu_attributes_preprocess_menu_link in Menu Attributes 8

Same name and namespace in other branches
  1. 7 menu_attributes.module \menu_attributes_preprocess_menu_link()

Implements MODULE_preprocess_HOOK().

Adds appropriate attributes to the list item.

See also

theme_menu_link()

File

./menu_attributes.module, line 269
Alters the menu item form to allow the administrator to specify additional attributes for the menu link

Code

function menu_attributes_preprocess_menu_link(&$variables) {
  $options =& $variables['element']['#localized_options'];
  $attributes =& $variables['element']['#attributes'];
  if (isset($options['item_attributes'])) {
    foreach ($options['item_attributes'] as $attribute => $value) {
      if (!empty($value)) {

        // Class get's special treatment, as it's an array and it should not
        // replace existing values.
        if ($attribute == 'class') {
          $value = is_array($value) ? explode(' ', $value) : $value;
          if (isset($attributes[$attribute])) {
            $value = array_merge($attributes[$attribute], $value);
          }
        }

        // Override the attribute.
        $attributes[$attribute] = $value;
      }
    }

    // Clean up, so we're not passing this to l().
    unset($options['item_attributes']);
  }
}