You are here

public function InviteSettingsForm::elementValidateNumber in User External Invite 8

Same name and namespace in other branches
  1. 2.0.x src/Form/InviteSettingsForm.php \Drupal\user_external_invite\Form\InviteSettingsForm::elementValidateNumber()

Validation handler to check for a positive integer on a field.

Parameters

$element:

\Drupal\Core\Form\FormStateInterface $form_state:

$complete_form:

File

src/Form/InviteSettingsForm.php, line 223

Class

InviteSettingsForm

Namespace

Drupal\user_external_invite\Form

Code

public function elementValidateNumber(&$element, FormStateInterface $form_state, &$complete_form) {
  $element_name = $element['#title']
    ->getUntranslatedString();
  $value = $form_state
    ->getValue($element['#name']);
  if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value <= 0)) {
    $form_state
      ->setErrorByName($element['#name'], $this
      ->t('@element needs to be a positive integer.', [
      '@element' => $element_name,
    ]));
  }
}