function rules_condition_data_is_form_alter
Form alter callback for the condition data_is.
Use multiple steps to configure the condition as the needed type of the value depends on the selected data.
Related topics
File
-
modules/
data.rules.inc, line 637
Code
function rules_condition_data_is_form_alter(&$form, &$form_state, $options, RulesAbstractPlugin $element) {
if (!empty($options['init']) && !isset($form_state['rules_element_step'])) {
unset($form['parameter']['op'], $form['parameter']['value']);
$form['negate']['#access'] = FALSE;
$form_state['rules_element_step'] = 'data_value';
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Continue'),
'#limit_validation_errors' => array(
array(
'parameter',
'data',
),
array(
'parameter',
'op',
),
),
'#submit' => array(
'rules_form_submit_rebuild',
),
);
// Clear the parameter mode for the value parameter, so its gets the proper
// default value based upon the type of the the selected data on rebuild.
unset($form_state['parameter_mode']['value']);
}
else {
// Change the data parameter to be not editable.
$form['parameter']['data']['settings']['#access'] = FALSE;
// @todo Improve display.
$form['parameter']['data']['info'] = array(
'#prefix' => '<p>',
'#markup' => t('<strong>Selected data:</strong> %selector', array(
'%selector' => $element->settings['data:select'],
)),
'#suffix' => '</p>',
);
// Limit the operations to what makes sense for the selected data type.
$info = $element->pluginParameterInfo();
$data_info = $info['value'];
if ($element->settings['op'] == 'IN') {
$data_info['type'] = entity_property_list_extract_type($data_info['type']);
}
if (!RulesData::typesMatch($data_info, array(
'type' => array(
'decimal',
'date',
),
))) {
$options =& $form['parameter']['op']['settings']['op']['#options'];
unset($options['<'], $options['>']);
}
// Remove 'contains' if it is not selected, as it is deprecated by the
// text comparison condition.
if ($element->settings['op'] != 'contains') {
unset($form['parameter']['op']['settings']['op']['#options']['contains']);
}
// Auto-refresh the form if the operation is changed, so the input form
// changes in case "is one of" requires a list value.
$form['parameter']['op']['settings']['op']['#ajax'] = rules_ui_form_default_ajax() + array(
'trigger_as' => array(
'name' => 'reload',
),
);
// Provide a reload button for non-JS users.
$form['reload'] = array(
'#type' => 'submit',
'#value' => t('Reload form'),
'#limit_validation_errors' => array(
array(
'parameter',
'data',
),
array(
'parameter',
'op',
),
),
'#submit' => array(
'rules_form_submit_rebuild',
),
'#ajax' => rules_ui_form_default_ajax(),
'#weight' => 5,
);
// Hide the reload button in case JS is enabled.
$form['reload']['#attributes'] = array(
'class' => array(
'rules-hide-js',
),
);
}
}