Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TextfieldWidget.php

function TextfieldWidget::formElement

Overrides StringTextfieldWidget::formElement

File

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

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);
    $allowed_formats = $this->getFieldSetting('allowed_formats');
    $element = $main_widget['value'];
    $element['#type'] = 'text_format';
    $element['#format'] = $items[$delta]->format ?? NULL;
    $element['#base_type'] = $main_widget['value']['#type'];
    if ($allowed_formats && !$this->isDefaultValueWidget($form_state)) {
        $element['#allowed_formats'] = $allowed_formats;
    }
    return $element;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal