You are here

public static function UcQuantity::validateQuantity in Ubercart 8.4

Form element validation handler for #type 'uc_quantity'.

Note that #required is validated by _form_validate() already.

File

uc_store/src/Element/UcQuantity.php, line 44

Class

UcQuantity
Provides a form element for Ubercart quantity input.

Namespace

Drupal\uc_store\Element

Code

public static function validateQuantity(&$element, FormStateInterface $form_state, &$complete_form) {
  if (!preg_match('/^\\d+$/', $element['#value'])) {
    $form_state
      ->setError($element, t('The quantity must be an integer.'));
  }
  elseif (empty($element['#allow_zero']) && !$element['#value']) {
    $form_state
      ->setError($element, t('The quantity cannot be zero.'));
  }
}