You are here

function node_reference_field_widget_form in References 7.2

Implements hook_field_widget_form().

File

node_reference/node_reference.module, line 659
Defines a field type for referencing one node from another.

Code

function node_reference_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  switch ($instance['widget']['type']) {
    case 'node_reference_autocomplete':
      $element += array(
        '#type' => 'textfield',
        '#default_value' => isset($items[$delta]['nid']) ? $items[$delta]['nid'] : NULL,
        '#autocomplete_path' => $instance['widget']['settings']['autocomplete_path'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/' . $field['field_name'],
        '#size' => $instance['widget']['settings']['size'],
        '#maxlength' => NULL,
        '#element_validate' => array(
          'node_reference_autocomplete_validate',
        ),
        '#value_callback' => 'node_reference_autocomplete_value',
      );
      break;
  }
  return array(
    'nid' => $element,
  );
}