You are here

function optionwidgets_select_process in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 6.3 modules/optionwidgets/optionwidgets.module \optionwidgets_select_process()
  2. 6.2 modules/optionwidgets/optionwidgets.module \optionwidgets_select_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_select_process'
optionwidgets_elements in modules/optionwidgets/optionwidgets.module
Implementation of FAPI hook_elements().

File

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

Code

function optionwidgets_select_process($element, $edit, &$form_state, $form) {
  $field_name = $element['#field_name'];
  $field = $form['#field_info'][$field_name];
  $field_key = $element['#columns'][0];
  if (!$form_state['submitted']) {
    $element['#value'] = optionwidgets_data2form($element, $element['#default_value'], $field);
  }
  $options = optionwidgets_options($field);
  $element[$field_key] = array(
    '#type' => 'select',
    '#title' => $element['#title'],
    '#description' => $element['#description'],
    '#required' => $field['required'],
    '#multiple' => $field['multiple'],
    '#options' => $options,
    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
  );

  // Make sure field info will be available to the validator which
  // does not get the values in $form.
  // TODO for some reason putting the $field array into $form_state['storage']
  // causes the node's hook_form_alter to be invoked twice, garbling the
  // results. Need to investigate why that is happening (a core bug?), but
  // in the meantime avoid using $form_state['storage'] to store anything.
  $form_state['#field_info'][$field['field_name']] = $field;
  return $element;
}