function OptionsWidgetBase::extractFormValues

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase::extractFormValues()

File

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

Class

OptionsWidgetBase
Base class for the 'options_*' widgets.

Namespace

Drupal\Core\Field\Plugin\Field\FieldWidget

Code

public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state) : void {
  $field_name = $this->fieldDefinition
    ->getName();
  // Normalize single-valued widgets (radios, single select) that return a
  // scalar value to an array for consistent processing in massageFormValues.
  $path = array_merge($form['#parents'], [
    $field_name,
  ]);
  $key_exists = NULL;
  $values = NestedArray::getValue($form_state->getValues(), $path, $key_exists);
  if ($key_exists && !is_array($values)) {
    $form_state->setValue($path, [
      $values,
    ]);
  }
  parent::extractFormValues($items, $form, $form_state);
}

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