You are here

function optionwidgets_data2form in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 6.3 modules/optionwidgets/optionwidgets.module \optionwidgets_data2form()
  2. 6 modules/optionwidgets/optionwidgets.module \optionwidgets_data2form()

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.

3 calls to optionwidgets_data2form()
optionwidgets_buttons_process in modules/optionwidgets/optionwidgets.module
Process an individual element.
optionwidgets_onoff_process in modules/optionwidgets/optionwidgets.module
Process an individual element.
optionwidgets_select_process in modules/optionwidgets/optionwidgets.module
Process an individual element.

File

modules/optionwidgets/optionwidgets.module, line 342
Defines selection, check box and radio button widgets for text and numeric fields.

Code

function optionwidgets_data2form($element, $items, $field) {
  $field_key = $element['#columns'][0];
  $options = optionwidgets_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'] || $element['#type'] == 'optionwidgets_onoff') {
    return array(
      $field_key => $keys,
    );
  }
  else {
    return !empty($keys) ? array(
      $field_key => $value,
    ) : array();
  }
}