optionwidgets_data2form($element, $items, $field)
contributions/cck/modules/optionwidgets/optionwidgets.module, line 323
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.
<?php
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();
}
}
?>