You are here

protected function ShippingInformation::hasRateSelected in Commerce Shipping 8.2

Determines whether a shipping rate is currently selected.

Parameters

array $pane_form: The pane form.

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

Return value

bool Whether a shipping rate is currently selected.

1 call to ShippingInformation::hasRateSelected()
ShippingInformation::buildPaneForm in src/Plugin/Commerce/CheckoutPane/ShippingInformation.php
Builds the pane form.

File

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

Class

ShippingInformation
Provides the shipping information pane.

Namespace

Drupal\commerce_shipping\Plugin\Commerce\CheckoutPane

Code

protected function hasRateSelected(array $pane_form, FormStateInterface $form_state) {
  $user_input = NestedArray::getValue($form_state
    ->getUserInput(), $pane_form['#parents']);
  if (empty($user_input['shipments'])) {
    return FALSE;
  }

  // Loop over the shipments input to see if a shipping rate was selected.
  foreach ($user_input['shipments'] as $values) {
    if (!empty(array_filter($values['shipping_method']))) {
      return TRUE;
    }
  }
  return FALSE;
}