You are here

public function OrderCreateForm::validateForm in Ubercart 8.4

Form validation 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 FormBase::validateForm

File

uc_order/src/Form/OrderCreateForm.php, line 244

Class

OrderCreateForm
Creates a new order and redirect to its edit screen.

Namespace

Drupal\uc_order\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  switch ($form_state
    ->getValue('customer_type')) {
    case 'search':
      if (!$form_state
        ->hasValue([
        'customer',
        'uid',
      ])) {
        $form_state
          ->setErrorByName('customer][uid', $this
          ->t('Please select a customer.'));
      }
      break;
    case 'create':
      $email = trim($form_state
        ->getValue([
        'customer',
        'email',
      ]));
      $uid = \Drupal::database()
        ->query('SELECT uid FROM {users_field_data} WHERE mail LIKE :mail', [
        ':mail' => $email,
      ])
        ->fetchField();
      if ($uid) {
        $form_state
          ->setErrorByName('customer][mail', $this
          ->t('An account already exists for that e-mail.'));
      }
      break;
  }
}