You are here

function context_reaction_menu::options_form in Context 6.3

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

Provide a form element that allow the admin to chose a menu item.

Overrides context_reaction::options_form

File

plugins/context_reaction_menu.inc, line 10

Class

context_reaction_menu
Expose menu items as context reactions.

Code

function options_form($context) {
  $menus = menu_parent_options(array_reverse(menu_get_menus()), NULL);
  $root_menus = array();
  foreach ($menus as $key => $name) {
    $id = explode(':', $key);
    if ($id[1] == '0') {
      $root_menus[$id[0]] = check_plain($name);
    }
    else {
      $link = menu_link_load($id[1]);
      $identifier = $link['link_path'];
      $root_menu = $root_menus[$id[0]];
      while (isset($menus[$root_menu][$identifier])) {
        $identifier .= "'";
      }
      $menus[$root_menu][$identifier] = $name;
    }
    unset($menus[$key]);
  }
  array_unshift($menus, "-- " . t('None') . " --");
  return array(
    '#title' => $this->title,
    '#description' => $this->description,
    '#options' => $menus,
    '#type' => 'select',
    '#default_value' => $this
      ->fetch_from_context($context),
  );
}