public static function ShippingInformation::clearValues in Commerce Shipping 8.2
Clears user input of selected shipping rates.
This is required to prevent invalid options being selected is a shipping rate is no longer available, when the selected address is updated or when the rates recalculation is explicitly triggered.
Parameters
array $element: The element.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
array The element.
File
- src/
Plugin/ Commerce/ CheckoutPane/ ShippingInformation.php, line 487
Class
- ShippingInformation
- Provides the shipping information pane.
Namespace
Drupal\commerce_shipping\Plugin\Commerce\CheckoutPaneCode
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 (in_array($triggering_element_name, [
'recalculate_shipping',
'select_address',
], TRUE)) {
$user_input =& $form_state
->getUserInput();
$parents = $element['#parents'];
array_pop($parents);
$parents[] = 'shipments';
NestedArray::unsetValue($user_input, $parents);
}
return $element;
}