You are here

public static function ShipmentForm::clearValues in Commerce Shipping 8.2

Clears user input of selected shipping rates if recalculation occured.

This is required to prevent invalid options being selected is a shipping rate is no longer available.

Parameters

array $element: The element.

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

Return value

array The element.

File

src/Form/ShipmentForm.php, line 227

Class

ShipmentForm
Defines the shipment add/edit form.

Namespace

Drupal\commerce_shipping\Form

Code

public static function clearValues(array $element, FormStateInterface $form_state) {
  $triggering_element = $form_state
    ->getTriggeringElement();
  if (!$triggering_element) {
    return $element;
  }
  $triggering_element_name = end($triggering_element['#parents']);
  if ($triggering_element_name === 'recalculate_shipping') {
    $user_input =& $form_state
      ->getUserInput();
    unset($user_input['shipping_method']);
  }
  return $element;
}