1 list.module list_form_field_ui_field_edit_form_alter(&$form, &$form_state)

File

core/modules/field/modules/list/list.module, line 151
Defines list field types that can be used with the Options module.

Code

function list_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
  $field = $form['#field'];

  if (in_array($field['type'], array('list_integer', 'list_float', 'list_text'))) {

    // Use options_element default widget instead of field widget.
    $form['instance']['default_value_widget']['#access'] = FALSE;
    // Language is hardcoded to 'und' in field_ui_default_value_widget().
    $default_field_value = $form['instance']['default_value_widget'][$field['field_name']][LANGUAGE_NONE]['#default_value'];

    // Overwrite 'allowed_values' element.
    $form['field']['settings']['allowed_values']['#default_value_allowed'] = TRUE;
    $form['field']['settings']['allowed_values']['#default_value'] = $default_field_value;

    // Add proper default value inside validate callback.
    $form['#validate'][] = 'options_field_instance_settings_validate';
  }
}