Contributions API

optionwidgets_form2data

Definition

optionwidgets_form2data($element, $field)
contributions/cck/modules/optionwidgets/optionwidgets.module, line 349

Description

Helper function to transpose the values returned by submitting the widget to the format to be stored in the field. Can be called anywhere this transformation is needed.

Code

<?php
function optionwidgets_form2data($element, $field) {
  $field_key = $element['#columns'][0];
  $items = (array) $element[$field_key]['#value'];
  $options = optionwidgets_options($field);

  $values = array_values($items);

  if ($element['#type'] == 'optionwidgets_onoff' && ($values[0] === 0)) {
    $keys = array_keys($options);
    $values = array(array_key_exists(0, $keys) ? $keys[0] : NULL);
  }

  if (empty($values)) {
    $values[] = NULL;
  }
  $result = content_transpose_array_rows_cols(array($field_key => $values));
  return $result;
}
?>