You are here

protected function ProductVariationTitleWidget::selectVariationFromUserInput in Commerce Core 8.2

Selects a product variation from user input.

Parameters

\Drupal\commerce_product\Entity\ProductVariationInterface[] $variations: An array of product variations.

array $user_input: The user input.

Return value

\Drupal\commerce_product\Entity\ProductVariationInterface|null The selected variation or NULL if there's no user input (form viewed for the first time).

1 call to ProductVariationTitleWidget::selectVariationFromUserInput()
ProductVariationTitleWidget::formElement in modules/product/src/Plugin/Field/FieldWidget/ProductVariationTitleWidget.php
Returns the form for a single field widget.

File

modules/product/src/Plugin/Field/FieldWidget/ProductVariationTitleWidget.php, line 162

Class

ProductVariationTitleWidget
Plugin implementation of the 'commerce_product_variation_title' widget.

Namespace

Drupal\commerce_product\Plugin\Field\FieldWidget

Code

protected function selectVariationFromUserInput(array $variations, array $user_input) {
  $current_variation = NULL;
  if (!empty($user_input['variation']) && isset($variations[$user_input['variation']])) {
    $current_variation = $variations[$user_input['variation']];
  }
  return $current_variation;
}