You are here

function text_widget in Content Construction Kit (CCK) 6

Same name in this branch
  1. 6 examples/simple_field.php \text_widget()
  2. 6 examples/example_field.php \text_widget()
  3. 6 modules/text/text.module \text_widget()
Same name and namespace in other branches
  1. 5 text.module \text_widget()
  2. 6.3 modules/text/text.module \text_widget()
  3. 6.2 modules/text/text.module \text_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'][$field['field_name']] holds the field's form values.

$field: the field array

$items: array of default values for this field

$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

examples/simple_field.php, line 477
SIMPLE EXAMPLE. This is similar to to example_field but creates only a single widget formatted in the traditional manner, not using hook_elements. This example also omits all optional parts of the field module to create a simpler example for…

Code

function text_widget(&$form, &$form_state, $field, $items, $delta = 0) {
  $field_key = $element['#columns'][0];
  $element[$field_key] = array(
    '#type' => 'textarea',
    '#title' => t($field['widget']['label']),
    '#description' => t($field['widget']['description']),
    '#required' => $element['#required'],
    '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
    '#rows' => !empty($field['widget']['rows']) ? $field['widget']['rows'] : 1,
    '#weight' => 0,
  );
  return $element;
}