You are here

function context_ui_form_process in Context 5

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

Produces a context object from submitted form values.

Parameters

$form: A form array with submitted values

Return value

A context object

1 call to context_ui_form_process()
context_ui_form_submit in context_ui/context_ui_admin.inc
Submit handler for main context_ui form.

File

context_ui/context_ui_admin.inc, line 724

Code

function context_ui_form_process($form) {
  $context = new stdClass();

  // Context ns/attr/value definition
  $context->cid = $form['cid'] ? $form['cid'] : null;
  $context->system = $form['system'] ? $form['system'] : null;
  $context->namespace = $form['namespace'] ? $form['namespace'] : null;
  $context->attribute = $form['attribute'] ? $form['attribute'] : null;
  $context->value = $form['value'] ? $form['value'] : null;
  $context->status = 1;

  // all user defined contexts have status 1
  // Values for most item types
  $item_types = context_ui_types();
  foreach ($item_types as $element_id) {
    if (is_array($form['items'][$element_id])) {
      foreach ($form['items'][$element_id] as $option => $value) {
        if ($value) {
          $context->{$element_id}[] = $option;
        }
      }
    }
    else {
      if (isset($form['items'][$element_id]) && !empty($form['items'][$element_id])) {
        $context->{$element_id}[] = $form['items'][$element_id];
      }
    }
  }

  // Blocks must be done by region
  $context->block = array();
  global $theme_key;

  // Get list of "valid" available blocks
  $valid = _context_ui_get_blocks();
  $valid = $valid[0];
  foreach (system_region_list($theme_key) as $region => $label) {
    if ($blocks = $form['block']['regions'][$region]) {
      $blocks = explode(',', $blocks);
      $midpoint = array_search('system', $blocks);
      foreach ($blocks as $position => $bid) {
        if ($bid != 'system') {
          $block = $valid[$bid];
          $modifier = $position < $midpoint ? -10 : 10;
          $block->weight = $position - $midpoint + $modifier;
          $block->region = $region;
          $block->type = 'context_ui';
          $context->block[$block->bid] = $block;
        }
      }
    }
  }
  return $context;
}