function context_ui_form in Context 7.3
Same name and namespace in other branches
- 5 context_ui/context_ui_admin.inc \context_ui_form()
- 6.3 context_ui/export_ui/context_export_ui.class.php \context_ui_form()
- 6 context_ui/context_ui.admin.inc \context_ui_form()
- 6 context_ui/export_ui/context_export_ui.class.php \context_ui_form()
- 6.2 context_ui/context_ui.admin.inc \context_ui_form()
Generates the omnibus context definition editing form.
Parameters
$form: Form array to populate.
$form_state: Form state 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 107
Code
function context_ui_form(&$form, &$form_state) {
$conditions = array_keys(context_conditions());
sort($conditions);
$reactions = array_keys(context_reactions());
sort($reactions);
$context = $form_state['item'];
if (!empty($form_state['input'])) {
$context = _context_ui_rebuild_from_input($context, $form_state['input'], $conditions, $reactions);
}
$form['#base'] = 'context_ui_form';
$form['#theme'] = 'context_ui_form';
// Core context definition
$form['info']['#type'] = 'fieldset';
$form['info']['#tree'] = FALSE;
$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' => array(
'context-plugins-state',
),
),
'#type' => 'hidden',
),
'plugins' => array(
'#tree' => TRUE,
),
);
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' => array(
'context-plugins-state',
),
),
'#type' => 'hidden',
),
'plugins' => array(
'#tree' => TRUE,
),
);
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;
}
}
}