You are here

function context_condition_menu::execute in Context 6.3

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

Override of execute().

File

plugins/context_condition_menu.inc, line 85

Class

context_condition_menu
Expose menu items as a context condition.

Code

function execute() {
  if ($this
    ->condition_used()) {

    // Menu trail condition integration. Note that because of the way
    // menu_get_active_trail() is written this will often not work for active
    // menu items outside the standard navigation tree without the additional
    // helper code below.
    if (menu_get_active_menu_name() === 'navigation') {
      $item = menu_get_item();
      $menus = variable_get('context_condition_menu_selections', menu_get_menus());
      $params = array_values($menus);
      $params[] = $item['href'];
      $in_clause = implode(', ', array_fill(0, count($menus), "'%s'"));
      $query = "SELECT menu_name FROM {menu_links} WHERE menu_name IN ({$in_clause}) AND link_path = '%s' ORDER BY mlid ASC";
      if ($menu_name = db_result(db_query($query, $params))) {
        menu_set_active_menu_name($menu_name);
      }
    }
    $trail = menu_get_active_trail();
    foreach ($trail as $item) {
      if (!empty($item['href'])) {
        foreach ($this
          ->get_contexts($item['href']) as $context) {
          $this
            ->condition_met($context, $item['href']);
        }
      }
    }
  }
}