You are here

public function AddressPaneBase::process in Ubercart 8.4

Processes a checkout pane.

Parameters

\Drupal\uc_order\OrderInterface $order: The order that is being processed.

array $form: The checkout form array.

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

Return value

bool TRUE if the pane is valid, FALSE otherwise.

Overrides CheckoutPanePluginBase::process

File

uc_cart/src/Plugin/Ubercart/CheckoutPane/AddressPaneBase.php, line 130

Class

AddressPaneBase
Provides a generic address pane that can be extended as required.

Namespace

Drupal\uc_cart\Plugin\Ubercart\CheckoutPane

Code

public function process(OrderInterface $order, array $form, FormStateInterface $form_state) {
  $pane = $this->pluginDefinition['id'];
  $source = $this
    ->sourcePaneId();
  $address = Address::create();
  $panes =& $form_state
    ->getValue('panes');
  foreach ($panes[$pane] as $field => $value) {
    if (isset($address->{$field})) {
      if (!empty($panes[$pane]['copy_address'])) {
        $address->{$field} = $panes[$source][$field];
      }
      else {
        $address->{$field} = $value;
      }
    }
  }
  if (isset($panes[$pane]['select_address']) && $panes[$pane]['select_address'] >= 0) {
    $addresses = uc_select_addresses(\Drupal::currentUser()
      ->id(), $pane);
    foreach ($addresses[$panes[$pane]['select_address']] as $field => $value) {
      $address->{$field} = $value;
    }
  }
  $order
    ->setAddress($pane, $address);
  return TRUE;
}