public function TaxonomyAutocompleteWidget::formElement

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

Overrides WidgetInterface::formElement

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php, line 50
Definition of Drupal\taxonomy\Plugin\field\widget\TaxonomyAutocompleteWidget.

Class

TaxonomyAutocompleteWidget
Plugin implementation of the 'taxonomy_autocomplete' widget.

Namespace

Drupal\taxonomy\Plugin\field\widget

Code

public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) {
  $field = $this->field;
  $tags = array();
  foreach ($items as $item) {
    $tags[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']);
  }
  $element += array(
    '#type' => 'textfield',
    '#default_value' => taxonomy_implode_tags($tags),
    '#autocomplete_path' => $this
      ->getSetting('autocomplete_path') . '/' . $field['field_name'],
    '#size' => $this
      ->getSetting('size'),
    '#placeholder' => $this
      ->getSetting('placeholder'),
    '#maxlength' => 1024,
    '#element_validate' => array(
      'taxonomy_autocomplete_validate',
    ),
  );
  return $element;
}