1 field_test.field.inc field_test_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element)

Implements hook_field_widget_form().

File

core/modules/field/tests/field_test/field_test.field.inc, line 195
Defines a field type and its formatters and widgets.

Code

function field_test_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  switch ($instance['widget']['type']) {
    case 'test_field_widget':
      $element += array(
        '#type' => 'textfield',
        '#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : '',
      );
      return array('value' => $element);

    case 'test_field_widget_multiple':
      $values = array();
      foreach ($items as $delta => $value) {
        $values[] = $value['value'];
      }
      $element += array(
        '#type' => 'textfield',
        '#default_value' => implode(', ', $values),
        '#element_validate' => array('field_test_widget_multiple_validate'),
      );
      return $element;
  }
}