function ddf_field_widget_options_select_form_alter in Dynamic dependent fields 7
Implements hook_field_widget_WIDGET_TYPE_form_alter().
File
- ./
ddf.module, line 344
Code
function ddf_field_widget_options_select_form_alter(&$element, &$form_state, $context) {
// Fix dependent fields with selects which loose multiple property for empty
// lists, see options_field_widget_form() function in options.module file.
$dependencies = ddf_load_dependencies($context['instance']['entity_type'], $context['instance']['bundle']);
if (empty($dependencies)) {
return;
}
$field = $context['field'];
foreach ($dependencies as $dependency) {
if ($dependency[1] == $field['field_name']) {
if (is_array($dependency[2]) && isset($dependency[2]['type']) && $dependency[2]['type'] != 'options') {
// Not options-type dependency, no special processing is required.
continue;
}
$ddf_processor = array(
'ddf_selector_element_process',
);
if (empty($element['#process'])) {
$info = element_info($element['#type']);
if (!empty($info['#process'])) {
$element['#process'] = array_merge($info['#process'], $ddf_processor);
}
}
else {
$element['#process'] = $ddf_processor;
}
$element['#value_callback'] = 'ddf_selector_element_value';
if (isset($element['#multiple']) && !$element['#multiple'] && $field['cardinality'] != 1) {
$element['#multiple'] = TRUE;
}
}
}
}