You are here

public static function ShippingInformation::autoRecalculateProcess in Commerce Shipping 8.2

Pane form #process callback: adds recalculation settings.

Parameters

array $element: The form element.

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

Return value

array The modified element.

File

src/Plugin/Commerce/CheckoutPane/ShippingInformation.php, line 366

Class

ShippingInformation
Provides the shipping information pane.

Namespace

Drupal\commerce_shipping\Plugin\Commerce\CheckoutPane

Code

public static function autoRecalculateProcess(array $element, FormStateInterface $form_state) {
  if ($element['#auto_recalculate']) {
    $recalculate_button_selector = $element['recalculate_shipping']['#attributes']['data-drupal-selector'];
    $element['#attached']['library'][] = 'commerce_shipping/shipping_checkout';
    $element['#attached']['drupalSettings']['commerceShipping'] = [
      'wrapper' => '#' . $element['#wrapper_id'],
      'recalculateButtonSelector' => '[data-drupal-selector="' . $recalculate_button_selector . '"]',
    ];
    $element['recalculate_shipping']['#attributes']['class'][] = 'js-hide';
  }
  return $element;
}