You are here

public function OrderReassignForm::submitForm in Commerce Core 8.2

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

modules/order/src/Form/OrderReassignForm.php, line 121

Class

OrderReassignForm
Provides a form for assigning orders to a different customer.

Namespace

Drupal\commerce_order\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this
    ->submitCustomerForm($form, $form_state);
  $values = $form_state
    ->getValues();

  /** @var \Drupal\user\UserInterface $user */
  $user = $this->userStorage
    ->load($values['uid']);
  $this->orderAssignment
    ->assign($this->order, $user);
  $this
    ->messenger()
    ->addMessage($this
    ->t('The order %label has been assigned to customer %customer.', [
    '%label' => $this->order
      ->label(),
    '%customer' => $this->order
      ->getCustomer()
      ->label(),
  ]));
  $form_state
    ->setRedirectUrl($this->order
    ->toUrl('collection'));
}