function OptionsWidgetBase::formElement

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase::formElement()
  2. 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase::formElement()
  3. 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase::formElement()

Overrides WidgetInterface::formElement

2 calls to OptionsWidgetBase::formElement()
OptionsButtonsWidget::formElement in core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php
OptionsSelectWidget::formElement in core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php
2 methods override OptionsWidgetBase::formElement()
OptionsButtonsWidget::formElement in core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php
OptionsSelectWidget::formElement in core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php, line 68

Class

OptionsWidgetBase
Base class for the 'options_*' widgets.

Namespace

Drupal\Core\Field\Plugin\Field\FieldWidget

Code

public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    // Prepare some properties for the child methods to build the actual form
    // element.
    $this->required = $element['#required'];
    $this->multiple = $this->fieldDefinition
        ->getFieldStorageDefinition()
        ->isMultiple();
    $this->has_value = isset($items[0]->{$this->column});
    // Add our custom validator.
    $element['#element_validate'][] = [
        static::class,
        'validateElement',
    ];
    $element['#key_column'] = $this->column;
    // The rest of the $element is built by child method implementations.
    return $element;
}

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