You are here

function context_menu_set_active in Context 6

Same name and namespace in other branches
  1. 6.2 context.core.inc \context_menu_set_active()

Iterates through a provided links array for use with theme_links() (e.g. from menu_primary_links()) and provides an active class for any items that have a path that matches an active context.

Parameters

$links: An array of links.

$reset: A boolean flag for resetting the static cache.

Return value

A modified links array.

1 call to context_menu_set_active()
context_preprocess_page in ./context.core.inc
Implementation of preprocess_page().

File

./context.core.inc, line 537

Code

function context_menu_set_active($links = array(), $reset = FALSE) {
  $active_paths = context_active_values('menu');

  // Iterate through the provided links and build a new set of links
  // that includes active classes
  $new_links = array();
  if (!empty($links)) {
    foreach ($links as $key => $link) {
      if (!empty($link['href']) && in_array($link['href'], $active_paths)) {
        if (isset($links['attributes']['class'])) {
          $link['attributes']['class'] .= ' active';
        }
        else {
          $link['attributes']['class'] = 'active';
        }
        if (strpos(' active', $key) === FALSE) {
          $new_links[$key . ' active'] = $link;
        }
      }
      else {
        $new_links[$key] = $link;
      }
    }
  }
  return $new_links;
}