You are here

class context_og_condition_group_type in Context OG 7.2

Same name and namespace in other branches
  1. 6.3 plugins/context_og_condition_group_type.inc \context_og_condition_group_type
  2. 7 plugins/context_og_condition_group_type.inc \context_og_condition_group_type

Expose organic groups group types as a context condition.

Hierarchy

Expanded class hierarchy of context_og_condition_group_type

3 string references to 'context_og_condition_group_type'
context_og_context_page_reaction in ./context_og.module
context_og_context_plugins in ./context_og.module
context_og_context_registry in ./context_og.module
Implementation of hook_context_registry().

File

plugins/context_og_condition_group_type.inc, line 6

View source
class context_og_condition_group_type extends context_condition {
  function condition_values() {
    $values = array(
      '_none_' => t('Not in any group'),
      '_any_' => t('In any group'),
    );
    foreach (node_type_get_types() as $type) {
      if (og_is_group_type('node', $type->type)) {
        $values[$type->type] = $type->name;
      }
    }
    return $values;
  }
  function options_form($context) {
    $defaults = $this
      ->fetch_from_context($context, 'options');
    return array(
      'node_form' => array(
        '#title' => t('Set on node form'),
        '#type' => 'checkbox',
        '#description' => t('Set this context on node forms'),
        '#default_value' => isset($defaults['node_form']) ? $defaults['node_form'] : TRUE,
      ),
    );
  }
  function execute($group) {
    $node_form = arg(0) == 'node' && (is_numeric(arg(1)) && arg(2) == 'edit' || arg(1) == 'add');
    if (!empty($group) && $group['group_type'] == 'node') {
      $node = entity_load_single($group['group_type'], $group['gid']);
      $type = $node ? $node->type : '_none_';
      $contexts = $this
        ->get_contexts($type);
      $this->values[$type] = array();

      // check if we are in _any_ group as well
      if ($type != '_none_') {
        $allcontexts = $this
          ->get_contexts('_any_');
        $this->values['_any_'] = array();
        foreach ($allcontexts as $acontext) {
          $options = $this
            ->fetch_from_context($acontext, 'options');
          if (!$node_form || !empty($options['node_form'])) {
            $this
              ->condition_met($acontext, '_any_');
          }
        }
      }
      foreach ($contexts as $context) {
        $options = $this
          ->fetch_from_context($context, 'options');

        // The condition is met unless we are looking at a node form
        // and the "Set on node form" option is unchecked.
        if (!$node_form || !empty($options['node_form'])) {
          $this
            ->condition_met($context, $type);
        }
      }
    }
    else {
      $no_group_contexts = $this
        ->get_contexts('_none_');
      $this
        ->get_contexts('_none_');
      $this->values['_none_'] = array();
      foreach ($no_group_contexts as $context) {
        $options = $this
          ->fetch_from_context($context, 'options');
        if (!$node_form || !empty($options['node_form'])) {
          $this
            ->condition_met($context, '_none_');
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
context_condition::$description property
context_condition::$plugin property
context_condition::$title property
context_condition::$values property
context_condition::condition_form function Condition form. 3
context_condition::condition_form_submit function Condition form submit handler. 2
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. 2
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. 2
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_og_condition_group_type::condition_values function Condition values. Overrides context_condition::condition_values
context_og_condition_group_type::execute function
context_og_condition_group_type::options_form function Options form. Provide additional options for your condition. Overrides context_condition::options_form