You are here

function optionwidgets_widget in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 5 optionwidgets.module \optionwidgets_widget()
  2. 6.3 modules/optionwidgets/optionwidgets.module \optionwidgets_widget()
  3. 6.2 modules/optionwidgets/optionwidgets.module \optionwidgets_widget()

Implementation of hook_widget().

Attach a single form element to the form. It will be built out and validated in the callback(s) listed in hook_elements. We build it out in the callbacks rather than here in hook_widget so it can be plugged into any module that can provide it with valid $field information.

Content module will set the weight, field name and delta values for each form element. This is a change from earlier CCK versions where the widget managed its own multiple values.

If there are multiple values for this field, the content module will call this function as many times as needed.

Parameters

$form: the entire form array, $form['#node'] holds node information

$form_state: the form_state, $form_state['values'] holds the form values.

$field: the field array

$items: an array of default values for this element

$delta: the order of this item in the array of subelements (0, 1, 2, etc)

Return value

the form item for a single element for this field

File

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

Code

function optionwidgets_widget(&$form, &$form_state, $field, $items, $delta = NULL) {
  $element = array(
    '#type' => $field['widget']['type'],
    '#default_value' => !empty($items) ? $items : array(),
  );
  return $element;
}