function context_ui_form_process in Context 6.2
Same name and namespace in other branches
- 5 context_ui/context_ui_admin.inc \context_ui_form_process()
- 6.3 context_ui/export_ui/context_export_ui.class.php \context_ui_form_process()
- 6 context_ui/context_ui.admin.inc \context_ui_form_process()
- 6 context_ui/export_ui/context_export_ui.class.php \context_ui_form_process()
- 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 878
Code
function context_ui_form_process($form) {
$context = new stdClass();
// Context ns/attr/value definition
foreach (array(
'cid',
'system',
'namespace',
'attribute',
'value',
'description',
) as $item) {
$context->{$item} = isset($form[$item]) ? $form[$item] : NULL;
}
$context->status = 1;
// all user defined contexts have status 1
// Retrieve values for conditions and reactions
foreach (context_conditions() + context_reactions() as $id => $element) {
if (is_array($form['items'][$id])) {
if (isset($element['#type']) && $element['#type'] == 'checkboxes') {
$items = array_keys(array_filter($form['items'][$id]));
}
else {
$items = array_filter($form['items'][$id]);
}
}
else {
$items = isset($form['items'][$id]) ? $form['items'][$id] : '';
}
if (!empty($items)) {
$context->{$id} = $items;
}
}
// Blocks must be done by region
$theme_key = variable_get('theme_default', 'garland');
// 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) {
// Don't initialize the block array until we're actually sure
// the context contains blocks.
if (!isset($context->block)) {
$context->block = array();
}
if ($bid != 'system') {
$block = $valid[$bid];
//use the max block weight to calculate modifier
$modifier = $position < $midpoint ? $form['block']['max_block_weight'] * -1 : $form['block']['max_block_weight'];
$block->weight = $position - $midpoint + $modifier;
$block->region = $region;
$block->type = 'context_ui';
$context->block[$block->bid] = $block;
}
}
}
}
return $context;
}