You are here

function menu_attributes_menu_link_alter in Menu Attributes 7

Same name and namespace in other branches
  1. 6.2 menu_attributes.module \menu_attributes_menu_link_alter()
  2. 6 menu_attributes.module \menu_attributes_menu_link_alter()

Implements hook_menu_link_alter().

File

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

Code

function menu_attributes_menu_link_alter(&$item, $menu) {
  if (isset($item['options']['attributes']) && is_array($item['options']['attributes'])) {

    // Filter out blank attributes.
    foreach ($item['options']['attributes'] as $key => $value) {
      if (is_array($value) && empty($value) || is_string($value) && !drupal_strlen($value)) {
        unset($item['options']['attributes'][$key]);
      }
    }

    // Convert classes to an array.
    if (isset($item['options']['attributes']['class']) && is_string($item['options']['attributes']['class'])) {
      $item['options']['attributes']['class'] = array_filter(explode(' ', $item['options']['attributes']['class']));
    }
  }
}