You are here

public function AutocompleteWidget::formElement in Entity reference 8

Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().

Overrides AutocompleteWidgetBase::formElement

File

lib/Drupal/entityreference/Plugin/field/widget/AutocompleteWidget.php, line 44
Definition of Drupal\entityreference\Plugin\field\widget\AutocompleteWidget.

Class

AutocompleteWidget
Plugin implementation of the 'entityreference autocomplete' widget.

Namespace

Drupal\entityreference\Plugin\field\widget

Code

public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) {

  // We let the Field API handles multiple values for us, only take
  // care of the one matching our delta.
  if (isset($items[$delta])) {
    $items = array(
      $items[$delta],
    );
  }
  else {
    $items = array();
  }
  $element = $this
    ->prepareElement($items, $delta, $element, $langcode, $form, $form_state, 'entityreference/autocomplete/single');
  return array(
    'target_id' => $element,
  );
}