You are here

function cami_preprocess_menu_link in Custom Active Menu Item 7

Implements hook_preprocess_menu_link().

File

./cami.module, line 82
Allows to specify which menu item is active and the classes that will be added to it.

Code

function cami_preprocess_menu_link(&$variables) {
  if (isset($variables['element']['#localized_options']['cami']['pages'])) {
    $pages = $variables['element']['#localized_options']['cami']['pages'];
    $path = drupal_get_path_alias(current_path());

    // Compare with the internal and path alias (if any).
    $page_match = drupal_match_path($path, $pages);
    if ($path != current_path()) {
      $page_match = $page_match || drupal_match_path(current_path(), $pages);
    }
  }
  if (isset($page_match) && $page_match) {
    $variables['element']['#attributes']['class'][] = variable_get('cami_li_classes', 'active-trail');
    $variables['element']['#localized_options']['attributes']['class'][] = variable_get('cami_a_classes', 'active');
  }
}