function TextfieldWidget::formElement

Same name in other branches
  1. 9 core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php \Drupal\text\Plugin\Field\FieldWidget\TextfieldWidget::formElement()
  2. 10 core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php \Drupal\text\Plugin\Field\FieldWidget\TextfieldWidget::formElement()
  3. 11.x core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php \Drupal\text\Plugin\Field\FieldWidget\TextfieldWidget::formElement()

Overrides StringTextfieldWidget::formElement

File

core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php, line 26

Class

TextfieldWidget
Plugin implementation of the 'text_textfield' widget.

Namespace

Drupal\text\Plugin\Field\FieldWidget

Code

public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $main_widget = parent::formElement($items, $delta, $element, $form, $form_state);
    $element = $main_widget['value'];
    $element['#type'] = 'text_format';
    $element['#format'] = isset($items[$delta]->format) ? $items[$delta]->format : NULL;
    $element['#base_type'] = $main_widget['value']['#type'];
    return $element;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.