function menu_position_activate_rule in Menu Position 7.2
Same name and namespace in other branches
- 7 menu_position.module \menu_position_activate_rule()
Evaluates all rules based on the given path.
Parameters
$rule: The rule that should be activated.
$context: A small context variable used by the menu_position module.
$set_breadcrumb: Whether the breadcrumb still needs to be set or not.
1 call to menu_position_activate_rule()
- menu_position_evaluate_rules in ./
menu_position.module - Evaluates all rules based on a given context.
File
- ./
menu_position.module, line 307 - Provides menu links for dynamic positioning of nodes based on configurable rules.
Code
function menu_position_activate_rule($rule, $context, $set_breadcrumb) {
// Retrieve menu item specified in the rule.
$menu_item = menu_link_load($rule->mlid);
// Sanity check: if the menu link doesn't exist abort processing the rule.
if (!$menu_item) {
return FALSE;
}
// Reset the menu trail that views may have set.
$original_router_item = menu_get_item();
if ($original_router_item['page_callback'] == 'views_page') {
$preferred =& drupal_static('menu_link_get_preferred');
unset($preferred[$context['path']]);
}
// Set the active path for the rule's menu.
menu_tree_set_path($rule->menu_name, $menu_item['link_path']);
// Get the default preferred link and save it so that it can be used in
// place of the rule's menu link when menu trees are rendered.
menu_position_set_link($rule->rid, menu_link_get_preferred());
// Allow the rule's parent menu item to show "expanded" status.
menu_position_expand_parent_link($rule->plid);
// Alter the active trail if breadcrumbs still need to be set.
if ($set_breadcrumb) {
// Manually set the preferred link for this path so that
// menu_get_active_trail() returns the proper trail.
$preferred_links =& drupal_static('menu_link_get_preferred');
$preferred_links[$_GET['q']][MENU_PREFERRED_LINK] = menu_link_get_preferred($menu_item['link_path']);
// Remove the menu position router from the end of the trail.
$active_trail = menu_set_active_trail();
array_pop($active_trail);
menu_set_active_trail($active_trail);
}
return TRUE;
}