class context_condition_menu

  1. cis7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc context_condition_menu
  2. cle7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc context_condition_menu
  3. elmsmedia7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc context_condition_menu
  4. icor7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc context_condition_menu
  5. meedjum_blog7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc context_condition_menu
  6. mooc7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc context_condition_menu

Expose menu items as a context condition.

Hierarchy

Expanded class hierarchy of context_condition_menu

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
context_condition::condition_met function Marks a context as having met this particular condition.
context_condition::condition_used function Check whether this condition is used by any contexts. Can be used to prevent expensive condition checks from being triggered when no contexts use this condition.
context_condition::editor_form function Context editor form for conditions.
context_condition::editor_form_submit function Context editor form submit handler.
context_condition::fetch_from_context function Retrieve options from the context provided.
context_condition::get_contexts function Retrieve all contexts with the condition value provided.
context_condition::options_form function Options form. Provide additional options for your condition.
context_condition::options_form_submit function Options form submit handler.
context_condition::settings_form function Settings form. Provide variable settings for your condition.
context_condition::__clone function Clone our references when we're being cloned.
context_condition::__construct function Constructor. Do not override.
context_condition_menu::condition_form function Override of condition_form(). Use multiselect widget. Overrides context_condition::condition_form
context_condition_menu::condition_form_submit function Override of condition_form_submit(). Trim any identifier padding for non-unique path menu items. Overrides context_condition::condition_form_submit
context_condition_menu::condition_values function Override of condition_values(). Overrides context_condition::condition_values
context_condition_menu::execute function Override of execute().

File

sites/all/modules/ulmus/context/plugins/context_condition_menu.inc, line 6

View source
class context_condition_menu extends context_condition {
  /**
   * Override of condition_values().
   */
  function condition_values() {
    if (module_exists('menu')) {
      $menus = menu_parent_options(menu_get_menus(), array('mlid' => 0));
      $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') . " --");
    }
    else {
      $menus = array();
    }
    return $menus;
  }

  /**
   * Override of condition_form().
   * Use multiselect widget.
   */
  function condition_form($context) {
    $form = parent::condition_form($context);
    $menu_count = count($form['#options'], COUNT_RECURSIVE);
    $form['#type'] = 'select';
    $form['#multiple'] = TRUE;
    $form['#attributes'] = array('size' => $menu_count > 20 ? 20 : $menu_count);
    return $form;
  }

  /**
   * Override of condition_form_submit().
   * Trim any identifier padding for non-unique path menu items.
   */
  function condition_form_submit($values) {
    // Trim any identifier padding for non-unique path menu items.
    $values = parent::condition_form_submit($values);
    $trimmed = array();
    foreach ($values as $key => $value) {
      $trimmed[trim($key, "'")] = trim($value, "'");
    }
    return $trimmed;
  }

  /**
   * Override of execute().
   */
  function execute() {
    if ($this->condition_used()) {
      $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']);
          }
        }
      }
    }
  }
}
2 string references to 'context_condition_menu'
_context_context_plugins in sites/all/modules/ulmus/context/context.plugins.inc
Context plugins.
_context_context_registry in sites/all/modules/ulmus/context/context.plugins.inc
Context registry.