function optionwidgets_form2data in Content Construction Kit (CCK) 6
Same name and namespace in other branches
- 6.3 modules/optionwidgets/optionwidgets.module \optionwidgets_form2data()
- 6.2 modules/optionwidgets/optionwidgets.module \optionwidgets_form2data()
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.
1 call to optionwidgets_form2data()
- optionwidgets_validate in modules/
optionwidgets/ optionwidgets.module - FAPI function to validate optionwidgets element.
File
- modules/
optionwidgets/ optionwidgets.module, line 307 - Defines selection, check box and radio button widgets for text and numeric fields.
Code
function optionwidgets_form2data($element, $items, $field) {
$field_key = $element['#columns'][0];
$options = optionwidgets_options($field);
$keys = isset($items[$field_key]) ? $items[$field_key] : array();
if (!is_array($keys)) {
$keys = array(
$keys,
);
}
$values = array();
foreach ($keys as $key => $value) {
if (array_key_exists($value, $options)) {
$values[] = $value;
}
}
if (empty($values)) {
if ($element['#type'] == 'optionwidgets_onoff') {
$keys = array_keys($options);
$values[] = array_key_exists(0, $keys) ? $keys[0] : '';
}
else {
$values[] = NULL;
}
}
return content_transpose_array_rows_cols(array(
$field_key => $values,
));
}