function context_ui_form_process in Context 6
Same name in this branch
- 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()
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.2 context_ui/context_ui.admin.inc \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
2 calls to context_ui_form_process()
- context_ui_form_submit in context_ui/
context_ui.admin.inc - Submit handler for main context_ui form.
- context_ui_form_submit in context_ui/
export_ui/ context_export_ui.class.php - Submit handler for main context_ui form.
File
- context_ui/
context_ui.admin.inc, line 843
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
foreach (array_keys(context_conditions()) as $id) {
if (is_array($form['items'][$id])) {
foreach ($form['items'][$id] as $option => $value) {
if (!empty($value)) {
$context->{$id}[] = $option;
}
}
}
else {
if (isset($form['items'][$id]) && !empty($form['items'][$id])) {
$context->{$id}[] = $form['items'][$id];
}
}
}
// Retrieve values for reactions -- preserve key => val associations
foreach (array_keys(context_reactions()) as $id) {
if (isset($form['items'][$id]) && !context_empty($form['items'][$id])) {
$context->{$id} = $form['items'][$id];
}
}
// 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];
$modifier = $position < $midpoint ? -20 : 20;
$block->weight = $position - $midpoint + $modifier;
$block->region = $region;
$block->type = 'context_ui';
$context->block[$block->bid] = $block;
}
}
}
}
return $context;
}