You are here

public function OrderTypeForm::validateForm in Commerce Core 8.2

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

modules/order/src/Form/OrderTypeForm.php, line 170

Class

OrderTypeForm
Provides an order type form.

Namespace

Drupal\commerce_order\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\state_machine\Plugin\Workflow\WorkflowInterface $workflow */
  $workflow = $this->workflowManager
    ->createInstance($form_state
    ->getValue('workflow'));

  // Verify "Place" transition.
  if (!$workflow
    ->getTransition('place')) {
    $form_state
      ->setError($form['workflow'], $this
      ->t('The @workflow workflow does not have a "Place" transition.', [
      '@workflow' => $workflow
        ->getLabel(),
    ]));
  }

  // Verify "draft" state.
  if (!$workflow
    ->getState('draft')) {
    $form_state
      ->setError($form['workflow'], $this
      ->t('The @workflow workflow does not have a "Draft" state.', [
      '@workflow' => $workflow
        ->getLabel(),
    ]));
  }

  // Remove the number pattern if the checkbox was unchecked.
  if (!$form_state
    ->getValue('generate_number')) {
    $form_state
      ->setValue('numberPattern', NULL);
  }
  $this
    ->validateTraitForm($form, $form_state);
}