function conditional_fields_states_handler_checkboxes in Conditional Fields 7.3
States handler for checkboxes.
File
- ./
conditional_fields.module, line 1778 - Define dependencies between fields based on their states and values.
Code
function conditional_fields_states_handler_checkboxes($field, $field_info, $options, &$state) {
// Checkboxes are actually different form fields, so the #states property
// has to include a state for each checkbox.
$checkboxes_selectors = array();
switch ($options['values_set']) {
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET:
foreach ($options['value'] as $value) {
$checkboxes_selectors[conditional_fields_field_selector($field[current($value)])] = array(
'checked' => TRUE,
);
}
break;
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX:
// We interpret this as: checkboxes whose values match the regular
// expression should be checked.
foreach ($field['#options'] as $key => $label) {
if (preg_match('/' . $options['value']['RegExp'] . '/', $key)) {
$checkboxes_selectors[conditional_fields_field_selector($field[$key])] = array(
'checked' => TRUE,
);
}
}
break;
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND:
foreach ($options['values'] as $value) {
$checkboxes_selectors[conditional_fields_field_selector($field[$value])] = array(
'checked' => TRUE,
);
}
break;
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR:
$checkboxes_selectors[] = 'xor';
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR:
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT:
foreach ($options['values'] as $value) {
$checkboxes_selectors[] = array(
conditional_fields_field_selector($field[$value]) => array(
'checked' => TRUE,
),
);
}
break;
}
$state = array(
$options['state'] => $checkboxes_selectors,
);
}