function OptionsSelectWidget::formElement
Same name in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget::formElement()
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget::formElement()
- 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget::formElement()
Overrides OptionsWidgetBase::formElement
1 method overrides OptionsSelectWidget::formElement()
- ModerationStateWidget::formElement in core/
modules/ content_moderation/ src/ Plugin/ Field/ FieldWidget/ ModerationStateWidget.php
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldWidget/ OptionsSelectWidget.php, line 30
Class
- OptionsSelectWidget
- Plugin implementation of the 'options_select' widget.
Namespace
Drupal\Core\Field\Plugin\Field\FieldWidgetCode
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$element += [
'#type' => 'select',
'#options' => $this->getOptions($items->getEntity()),
'#default_value' => $this->getSelectedOptions($items),
// Do not display a 'multiple' select box if there is only one option.
'#multiple' => $this->multiple && count($this->options) > 1,
];
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.