You are here

function context_reaction_menu::execute in Context 7.3

Same name and namespace in other branches
  1. 6.3 plugins/context_reaction_menu.inc \context_reaction_menu::execute()
  2. 6 plugins/context_reaction_menu.inc \context_reaction_menu::execute()

Provide active trail in all menus in which our path appears.

File

plugins/context_reaction_menu.inc, line 76

Class

context_reaction_menu
Expose menu items as context reactions.

Code

function execute(&$vars = NULL) {
  $menu_names = menu_get_active_menu_names();
  $active_paths = $this
    ->get_active_paths();
  foreach ($menu_names as $menu_name) {
    if (isset($active_paths[$menu_name])) {
      foreach ($active_paths[$menu_name] as $path) {
        if ($link = menu_link_get_preferred($path, $menu_name)) {
          $this
            ->set_active_trail_from_link($link);
          return;
        }
      }
    }
  }

  // None of the links can be found in their preferred menus. Instead we just try to find any of the paths in any
  // menu. Note that the preferred menu names list is still used but not always honoured.
  // We hope to not have to fall into this section as we could end up doing rather a lot of lookups.
  foreach ($active_paths as $menu_name => $paths) {
    foreach ($paths as $path) {
      if ($link = menu_link_get_preferred($path)) {
        $this
          ->set_active_trail_from_link($link);
        return;
      }
    }
  }
}