You are here

public static function AutocompleteDeluxeWidget::validateIntegerPositive in Autocomplete Deluxe 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldWidget/AutocompleteDeluxeWidget.php \Drupal\autocomplete_deluxe\Plugin\Field\FieldWidget\AutocompleteDeluxeWidget::validateIntegerPositive()

Form element validation handler for positive integer textfields.

File

src/Plugin/Field/FieldWidget/AutocompleteDeluxeWidget.php, line 302

Class

AutocompleteDeluxeWidget
Plugin implementation of the 'options_buttons' widget.

Namespace

Drupal\autocomplete_deluxe\Plugin\Field\FieldWidget

Code

public static function validateIntegerPositive(&$element, FormStateInterface $form_state, &$complete_form) {
  $value = $element['#value'];
  if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value <= 0)) {
    $form_state
      ->setError($element, \Drupal::translation()
      ->translate('%name must be a positive integer.', [
      '%name' => $element['#title'],
    ]));
  }
}