You are here

function tzfield_data2form in Time Zone Field 6

Helper function to transpose the values as stored in the database to the format the widget needs. Can be called anywhere this transformation is needed.

1 call to tzfield_data2form()
tzfield_select_process in ./tzfield.module
Process an individual select element.

File

./tzfield.module, line 449
Defines a field type for storing timezones.

Code

function tzfield_data2form($element, $items, $field) {
  $field_key = $element['#columns'][0];
  $options = tzfield_options($field);
  $items_transposed = content_transpose_array_rows_cols($items);
  $values = isset($items_transposed[$field_key]) && is_array($items_transposed[$field_key]) ? $items_transposed[$field_key] : array();
  $keys = array();
  foreach ($values as $value) {
    $key = array_search($value, array_keys($options));
    if (isset($key)) {
      $keys[] = $value;
    }
  }
  if ($field['multiple']) {
    return array(
      $field_key => $keys,
    );
  }
  else {
    return !empty($keys) ? array(
      $field_key => $value,
    ) : array();
  }
}