function optionwidgets_onoff_process in Content Construction Kit (CCK) 6.2
Same name and namespace in other branches
- 6.3 modules/optionwidgets/optionwidgets.module \optionwidgets_onoff_process()
- 6 modules/optionwidgets/optionwidgets.module \optionwidgets_onoff_process()
Process an individual element.
Build the form element. When creating a form using FAPI #process, note that $element['#value'] is already set.
The $fields array is in $form['#field_info'][$element['#field_name']].
1 string reference to 'optionwidgets_onoff_process'
- optionwidgets_elements in modules/
optionwidgets/ optionwidgets.module - Implementation of FAPI hook_elements().
File
- modules/
optionwidgets/ optionwidgets.module, line 276 - Defines selection, check box and radio button widgets for text and numeric fields.
Code
function optionwidgets_onoff_process($element, $edit, &$form_state, $form) {
$field_name = $element['#field_name'];
$field = $form['#field_info'][$field_name];
$field_key = $element['#columns'][0];
// See if this element is in the database format or the transformed format,
// and transform it if necessary.
if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) {
$element['#value'] = optionwidgets_data2form($element, $element['#default_value'], $field);
}
$options = optionwidgets_options($field);
$keys = array_keys($options);
$on_value = !empty($keys) && isset($keys[1]) ? $keys[1] : NULL;
$element[$field_key] = array(
'#type' => 'checkbox',
'#title' => isset($options[$on_value]) ? $options[$on_value] : '',
'#description' => $element['#description'],
'#required' => isset($element['#required']) ? $element['#required'] : $field['required'],
'#default_value' => isset($element['#value'][$field_key][0]) ? $element['#value'][$field_key][0] == $on_value : FALSE,
'#return_value' => $on_value,
);
// Set #element_validate in a way that it will not wipe out other
// validation functions already set by other modules.
if (empty($element['#element_validate'])) {
$element['#element_validate'] = array();
}
array_unshift($element['#element_validate'], 'optionwidgets_validate');
// Make sure field info will be available to the validator which
// does not get the values in $form.
$form_state['#field_info'][$field['field_name']] = $field;
return $element;
}