You are here

function context_ui_form in Context 6.3

Same name and namespace in other branches
  1. 5 context_ui/context_ui_admin.inc \context_ui_form()
  2. 6 context_ui/context_ui.admin.inc \context_ui_form()
  3. 6 context_ui/export_ui/context_export_ui.class.php \context_ui_form()
  4. 6.2 context_ui/context_ui.admin.inc \context_ui_form()
  5. 7.3 context_ui/export_ui/context_export_ui.class.php \context_ui_form()

Generates the omnibus context definition editing form.

Parameters

$op: The type of form to build. Either "add", "view" or "edit"

$cid: The db context identifier - required when $op == "edit"

Return value

A Drupal form array.

1 string reference to 'context_ui_form'
context.inc in context_ui/export_ui/context.inc

File

context_ui/export_ui/context_export_ui.class.php, line 80

Code

function context_ui_form(&$form, &$form_state) {
  $context = $form_state['item'];
  $form['#base'] = 'context_ui_form';
  $form['#theme'] = 'context_ui_form';

  // Core context definition
  $form['info']['#type'] = 'fieldset';
  $form['info']['#tree'] = FALSE;

  // Swap out name validator. Allow dashes.
  if (isset($form['info']['name']['#element_validate'])) {
    $form['info']['name']['#element_validate'] = array(
      'context_ui_edit_name_validate',
    );
  }
  $form['info']['tag'] = array(
    '#title' => t('Tag'),
    '#type' => 'textfield',
    '#required' => FALSE,
    '#maxlength' => 255,
    '#default_value' => isset($context->tag) ? $context->tag : '',
    '#description' => t('Example: <code>theme</code>') . '<br/>' . t('A tag to group this context with others.'),
  );
  $form['info']['description'] = array(
    '#title' => t('Description'),
    '#type' => 'textfield',
    '#required' => FALSE,
    '#maxlength' => 255,
    '#default_value' => isset($context->description) ? $context->description : '',
    '#description' => t('The description of this context definition.'),
  );

  // Condition mode
  $form['condition_mode'] = array(
    '#type' => 'checkbox',
    '#default_value' => isset($context->condition_mode) ? $context->condition_mode : FALSE,
    '#title' => t('Require all conditions'),
    '#description' => t('If checked, all conditions must be met for this context to be active. Otherwise, the first condition that is met will activate this context.'),
  );

  // Condition plugin forms
  $form['conditions'] = array(
    '#theme' => 'context_ui_plugins',
    '#title' => t('Conditions'),
    '#description' => t('Trigger the activation of this context'),
    '#tree' => TRUE,
    'selector' => array(
      '#type' => 'select',
      '#options' => array(
        0 => '<' . t('Add a condition') . '>',
      ),
      '#default_value' => 0,
    ),
    'state' => array(
      '#attributes' => array(
        'class' => 'context-plugins-state',
      ),
      '#type' => 'hidden',
    ),
    'plugins' => array(
      '#tree' => TRUE,
    ),
  );
  $conditions = array_keys(context_conditions());
  sort($conditions);
  foreach ($conditions as $condition) {
    if ($plugin = context_get_plugin('condition', $condition)) {
      $form['conditions']['plugins'][$condition] = array(
        '#tree' => TRUE,
        '#plugin' => $plugin,
        '#context_enabled' => isset($context->conditions[$condition]),
        // This flag is used at the theme layer.
        'values' => $plugin
          ->condition_form($context),
        'options' => $plugin
          ->options_form($context),
      );
      $form['conditions']['selector']['#options'][$condition] = $plugin->title;
    }
  }

  // Reaction plugin forms
  $form['reactions'] = array(
    '#theme' => 'context_ui_plugins',
    '#title' => t('Reactions'),
    '#description' => t('Actions to take when this context is active'),
    '#tree' => TRUE,
    'selector' => array(
      '#type' => 'select',
      '#options' => array(
        0 => '<' . t('Add a reaction') . '>',
      ),
      '#default_value' => 0,
    ),
    'state' => array(
      '#attributes' => array(
        'class' => 'context-plugins-state',
      ),
      '#type' => 'hidden',
    ),
    'plugins' => array(
      '#tree' => TRUE,
    ),
  );
  $reactions = array_keys(context_reactions());
  sort($reactions);
  foreach ($reactions as $reaction) {
    if ($plugin = context_get_plugin('reaction', $reaction)) {
      $form['reactions']['plugins'][$reaction] = $plugin
        ->options_form($context) + array(
        '#plugin' => $plugin,
        '#context_enabled' => isset($context->reactions[$reaction]),
      );
      $form['reactions']['selector']['#options'][$reaction] = $plugin->title;
    }
  }
  return $form;
}