You are here

function rb_misc_action_set_active_menu_item in Rules Bonus Pack 6

Same name and namespace in other branches
  1. 7 rb_misc.rules.inc \rb_misc_action_set_active_menu_item()

The 'rb_misc_action_set_active_menu_item' action.

File

./rb_misc.module, line 425
Miscellaneous conditions and actions for Rules.

Code

function rb_misc_action_set_active_menu_item($settings) {

  // 90 percent of the code below is shamelessly stolen from the menu_position
  // module, by JohnAlbin (http://drupal.org/user/32095). Cred to him!
  $configuration = explode(':', $settings['menu_item']);
  $menu_name = $configuration[0];
  $mlid = $configuration[1];

  // Retrieve menu item specified in the settings.
  $menu_item = menu_link_load($mlid);

  // Clone the original router item, but insert our menu_position path.
  $original_router_item = menu_get_item();
  $router_item = $original_router_item;
  $router_item['href'] = $menu_item['link_path'];
  $router_item['menu_name'] = $menu_name;

  // Even if we are denied access to the page, we still want to show the
  // navigational paths to the page.
  $router_item['access'] = TRUE;

  // Temporarily override the original router item.
  menu_set_item(NULL, $router_item);

  // The magic goes here. Cred to JohnAlbin.
  menu_position_precache_tree($router_item, $original_router_item, $menu_item['menu_name']);

  // Restore the original router item.
  menu_set_item(NULL, $original_router_item);

  // TODO: Find a way to add the 'active' CCS class to the menu item. I have
  // studied context_reaction_menu.inc in the Context module, but it has so far
  // not made me any wiser. //Itangalo.
}