function _ca_conditions_form_condition in Ubercart 6.2
Add a single condition's fieldset to the conditions form.
Parameters
$condition: The condition data array.
$trigger: The trigger name and data concerning the arguments that are passed in to the condition.
Return value
A form array representing the condition.
1 call to _ca_conditions_form_condition()
- _ca_conditions_form_tree in ca/
ca.admin.inc - Recursively add logical groups to the conditions form as fieldsets.
File
- ca/
ca.admin.inc, line 771 - Conditional actions overview UI.
Code
function _ca_conditions_form_condition($condition, $trigger) {
static $identifier = 0;
// Load the data for the conditions as defined by modules.
$condition_data = ca_load_condition();
// Condition name is a hard reference to the condition and so not editable.
$form['name'] = array(
'#type' => 'value',
'#value' => $condition['#name'],
);
// The title for this particular instance of this condition.
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $condition['#title'],
);
$form['argument_map'] = array(
'#type' => 'fieldset',
'#title' => t('Arguments'),
'#description' => t('Some triggers pass in multiple options for arguments related to a particular condition, so you must specify which options to use in the fields below.'),
'#collapsible' => TRUE,
);
// Setup a variable to decide if we can collapse the arguments fieldset.
$collapsed = TRUE;
// Cast to an array to accommodate conditions that need no arguments.
foreach ((array) $condition_data[$condition['#name']]['#arguments'] as $key => $value) {
// Load the available arguments for each entity as received by the
// trigger when it was pulled.
$options = ca_load_trigger_arguments($trigger, $value['#entity']);
// If we have more than one option for any argument, do not collapse.
if (count($options) > 1) {
$collapsed = FALSE;
}
$form['argument_map'][$key] = array(
'#type' => 'select',
'#title' => check_plain($value['#title']),
'#options' => $options,
'#default_value' => $condition['#argument_map'][$key],
);
}
$form['argument_map']['#collapsed'] = $collapsed;
// Whether or not to negate the result of this condition.
$form['settings']['negate'] = array(
'#type' => 'checkbox',
'#title' => t('Negate this condition.'),
'#description' => t('Return FALSE if the condition is TRUE and vice versa.'),
'#default_value' => $condition['#settings']['negate'],
);
// Get the callback for the condition we're displaying.
$callback = $condition_data[$condition['#name']]['#callback'] . '_form';
if (function_exists($callback)) {
// Load the trigger data.
$trigger_data = ca_load_trigger($trigger);
// Add the condition's form elements to the fieldset.
$form['settings'] += $callback(array(), $condition['#settings'], $trigger_data['#arguments']);
}
$form['remove'] = array(
'#type' => 'submit',
'#value' => t('Remove this condition'),
'#submit' => array(
'ca_conditions_form_remove_condition_submit',
),
'#attributes' => array(
'class' => 'ca-remove-confirm',
),
'#name' => 'remove_condition_group_' . $identifier++,
);
return $form;
}