public function TextfieldWidget::formElement

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

Overrides WidgetInterface::formElement

File

drupal/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php, line 55
Definition of Drupal\text\Plugin\field\widget\TextfieldWidget.

Class

TextfieldWidget
Plugin implementation of the 'text_textfield' widget.

Namespace

Drupal\text\Plugin\field\widget

Code

public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) {
  $main_widget = $element + array(
    '#type' => 'textfield',
    '#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
    '#size' => $this
      ->getSetting('size'),
    '#placeholder' => $this
      ->getSetting('placeholder'),
    '#maxlength' => $this->field['settings']['max_length'],
    '#attributes' => array(
      'class' => array(
        'text-full',
      ),
    ),
  );
  if ($this->instance['settings']['text_processing']) {
    $element = $main_widget;
    $element['#type'] = 'text_format';
    $element['#format'] = isset($items[$delta]['format']) ? $items[$delta]['format'] : NULL;
    $element['#base_type'] = $main_widget['#type'];
  }
  else {
    $element['value'] = $main_widget;
  }
  return $element;
}