You are here

function uuidreference_field_widget_form in UUID reference field 7

Implements hook_field_widget_form().

File

./uuidreference.module, line 227

Code

function uuidreference_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  switch ($instance['widget']['type']) {
    case 'uuidreference_autocomplete':
      $base = $instance['widget']['settings']['autocomplete_path'];
      $element += array(
        '#autocomplete_path' => $base . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/' . $field['field_name'],
        '#element_validate' => array(
          'uuidreference_autocomplete_validate',
        ),
        '#value_callback' => 'uuidreference_autocomplete_value',
      );

    // Intentionally fall through from autocomplete case to inherit textfield
    // defaults.
    case 'uuidreference_textfield':
      $element += array(
        '#type' => 'textfield',
        '#default_value' => isset($items[$delta]['target_uuid']) ? $items[$delta]['target_uuid'] : NULL,
      );
      break;
  }
  return array(
    'target_uuid' => $element,
  );
}