You are here

context_og_condition_group_node.inc in Context OG 7

File

plugins/context_og_condition_group_node.inc
View source
<?php

/**
 * Expose organic groups group nodes as a context condition.
 */
class context_og_condition_group_node extends context_condition {
  function condition_values() {
    $result = context_og_query_og_nodes();
    $values = array();
    foreach ($result as $group) {
      $type = node_type_get_name($group->type);
      $values[$group->nid] = $type . ': ' . $group->title;
    }
    return $values;
  }
  function condition_form($context) {
    $form = parent::condition_form($context);
    $form['#type'] = 'select';
    $form['#multiple'] = TRUE;
    return $form;
  }
  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) {
    if (isset($group)) {
      $node_form = arg(0) == 'node' && (is_numeric(arg(1)) && arg(2) == 'edit' || arg(1) == 'add');
      $contexts = $this
        ->get_contexts($group->etid);
      $this->values[$group->etid] = array();
      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, $group->etid);
        }
      }
    }
  }

}

Classes

Namesort descending Description
context_og_condition_group_node Expose organic groups group nodes as a context condition.