You are here

public function CustomerFormTrait::submitCustomerForm in Commerce Core 8.2

Submit handler for the customer select form.

Parameters

array $form: The parent form.

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

2 calls to CustomerFormTrait::submitCustomerForm()
OrderAddForm::submitForm in modules/order/src/Form/OrderAddForm.php
Form submission handler.
OrderReassignForm::submitForm in modules/order/src/Form/OrderReassignForm.php
Form submission handler.

File

modules/order/src/Form/CustomerFormTrait.php, line 133

Class

CustomerFormTrait
Provides a form for selecting the order's customer (uid and mail fields).

Namespace

Drupal\commerce_order\Form

Code

public function submitCustomerForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  if ($values['customer_type'] == 'existing') {
    $values['mail'] = User::load($values['uid'])
      ->getEmail();
  }
  else {
    $user = User::create([
      'name' => $values['mail'],
      'mail' => $values['mail'],
      'pass' => $values['generate'] ? user_password() : $values['pass'],
      'status' => TRUE,
    ]);
    $user
      ->save();
    $values['uid'] = $user
      ->id();
    if ($values['notify']) {
      _user_mail_notify('register_admin_created', $user);
    }
  }
  $form_state
    ->setValues($values);
}