You are here

function _options_form_to_storage in Drupal 7

Transforms submitted form values into field storage format.

1 call to _options_form_to_storage()
options_field_widget_validate in modules/field/modules/options/options.module
Form element validation handler for options element.

File

modules/field/modules/options/options.module, line 311
Defines selection, check box and radio button widgets for text and numeric fields.

Code

function _options_form_to_storage($element) {
  $values = array_values((array) $element['#value']);
  $properties = $element['#properties'];

  // On/off checkbox: transform '0 / 1' into the 'on / off' values.
  if ($element['#type'] == 'checkbox') {
    $values = array(
      $values[0] ? $element['#on_value'] : $element['#off_value'],
    );
  }

  // Filter out the 'none' option. Use a strict comparison, because
  // 0 == 'any string'.
  if ($properties['empty_option']) {
    $index = array_search('_none', $values, TRUE);
    if ($index !== FALSE) {
      unset($values[$index]);
    }
  }

  // Make sure we populate at least an empty value.
  if (empty($values)) {
    $values = array(
      NULL,
    );
  }
  $result = options_array_transpose(array(
    $element['#value_key'] => $values,
  ));
  return $result;
}