You are here

public function BuyItNowForm::submitForm in Ubercart 8.4

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormInterface::submitForm

File

uc_product/src/Form/BuyItNowForm.php, line 88

Class

BuyItNowForm
Defines a simple form for adding a product to the cart.

Namespace

Drupal\uc_product\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if (!$form_state
    ->getRedirect()) {
    $data = \Drupal::moduleHandler()
      ->invokeAll('uc_add_to_cart_data', [
      $form_state
        ->getValues(),
    ]);
    $msg = $this
      ->config('uc_cart.settings')
      ->get('add_item_msg');
    $cart = \Drupal::service('uc_cart.manager')
      ->get();
    $redirect = $cart
      ->addItem($form_state
      ->getValue('nid'), $form_state
      ->getValue('qty'), $data, $msg);
    if (isset($redirect)) {
      $form_state
        ->setRedirectUrl($redirect);
    }
  }
}