function context_reaction_menu::menu_set_active in Context 6
Same name and namespace in other branches
- 6.3 plugins/context_reaction_menu.inc \context_reaction_menu::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_reaction_menu::menu_set_active()
- context_reaction_menu::execute in plugins/
context_reaction_menu.inc - If primary + secondary links are pointed at the same menu, provide contextual trailing by default.
File
- plugins/
context_reaction_menu.inc, line 89
Class
- context_reaction_menu
- Expose menu items as context reactions.
Code
function menu_set_active($links = array(), $reset = FALSE) {
$new_links = array();
if (!empty($links)) {
$active_paths = $this
->get_active_paths();
// Iterate through the provided links and build a new set of links
// that includes active classes
foreach ($links as $key => $link) {
if (!empty($link['href']) && in_array($link['href'], $active_paths)) {
if (isset($link['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;
}