function TextfieldWidget::singleElementObject

Overrides StringTextfieldWidget::singleElementObject

File

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

Class

TextfieldWidget
Plugin implementation of the 'text_textfield' widget.

Namespace

Drupal\text\Plugin\Field\FieldWidget

Code

public function singleElementObject(FieldItemListInterface $items, $delta, Widget $widget, ElementInterface $form, FormStateInterface $form_state) : ElementInterface {
  $widget = parent::singleElementObject($items, $delta, $widget, $form, $form_state);
  $allowed_formats = $this->getFieldSetting('allowed_formats');
  $widget = $widget->getChild('value');
  $type = $widget->type;
  $widget = $widget->changeType(TextFormat::class);
  $widget->format = $items[$delta]->format ?? NULL;
  $widget->base_type = $type;
  if ($allowed_formats && !$this->isDefaultValueWidget($form_state)) {
    $widget->allowed_formats = $allowed_formats;
  }
  return $widget;
}

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