You are here

function field_test_field_widget in SimpleTest 7

Implement hook_field_widget().

Attach a single form element to the form. It will be built out and validated in the callback(s) listed in hook_element_info(). 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.

If there are multiple values for this field, the field 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 structure.

$instance: the instance 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

tests/field_test.module, line 518

Code

function field_test_field_widget(&$form, &$form_state, $field, $instance, $langcode, $items, $delta = 0) {
  $element = array(
    'value' => array(
      '#title' => $instance['label'],
      '#type' => 'textfield',
      '#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : '',
      '#required' => $instance['required'],
    ),
  );
  return $element;
}