You are here

public function SingleVariationWidget::extractFormValues in Commerce Core 8.2

Extracts field values from submitted form values.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values. This parameter is altered by reference to receive the incoming form values.

array $form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Overrides WidgetBase::extractFormValues

File

modules/product/src/Plugin/Field/FieldWidget/SingleVariationWidget.php, line 149

Class

SingleVariationWidget
Plugin implementation of the 'commerce_product_single_variation' widget.

Namespace

Drupal\commerce_product\Plugin\Field\FieldWidget

Code

public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state) {
  if ($this
    ->isDefaultValueWidget($form_state)) {
    $items
      ->filterEmptyItems();
    return;
  }
  $parents = [
    $this->fieldDefinition
      ->getName(),
    'widget',
  ];
  if ($form['#type'] != 'inline_entity_form') {
    $parents = array_merge($form['#parents'], $parents);
  }
  $element = NestedArray::getValue($form, $parents);

  /** @var \Drupal\commerce\Plugin\Commerce\InlineForm\EntityInlineFormInterface $inline_form */
  $inline_form = $element['entity']['#inline_form'];
  $values = $items
    ->getValue();
  $values[0] = [
    'entity' => $inline_form
      ->getEntity(),
  ];
  $items
    ->setValue($values);
  $items
    ->filterEmptyItems();
}