You are here

function field_test_field_widget_form in Drupal 7

Implements hook_field_widget_form().

File

modules/field/tests/field_test.field.inc, line 189
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;
  }
}