You are here

function _options_element_add_allowed_values_element in Options Element 7

Add options_element widget to form.

2 calls to _options_element_add_allowed_values_element()
options_element_form_field_ui_field_edit_form_alter in ./options_element.module
Implements hook_form_FORM_ID_alter().
options_element_form_field_ui_field_settings_form_alter in ./options_element.module
Implements hook_form_FORM_ID_alter().

File

./options_element.module, line 275
Defines an "options" form element type for entering select list options.

Code

function _options_element_add_allowed_values_element(&$form, $element) {
  $default_element = array(
    '#type' => 'options',
    '#key_type' => 'mixed',
    // Optimal for now.
    '#key_type_toggle' => t('Custom keys'),
    '#key_type_toggled' => TRUE,
    '#after_build' => array(
      'options_element_field_settings_after_build',
    ),
    '#access' => $form['field']['settings']['allowed_values']['#access'],
    '#default_value' => '',
    // Pass original data for validating.
    '#original' => array(
      '#title' => $form['field']['settings']['allowed_values']['#title'],
      '#field_has_data' => $form['field']['settings']['allowed_values']['#field_has_data'],
      '#field' => $form['field']['settings']['allowed_values']['#field'],
      '#field_type' => $form['field']['settings']['allowed_values']['#field_type'],
    ),
  );
  $element = drupal_array_merge_deep($default_element, $element);
  $form['field']['settings']['allowed_values'] = $element;

  // Set proper allowed values in $form_state.
  $form['#validate'][] = 'options_element_field_settings_validate';
}