You are here

public function TermForm::validateForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/src/TermForm.php \Drupal\taxonomy\TermForm::validateForm()
  2. 9 core/modules/taxonomy/src/TermForm.php \Drupal\taxonomy\TermForm::validateForm()

Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level validation handler, otherwise an exception will be thrown.

Overrides ContentEntityForm::validateForm

File

core/modules/taxonomy/src/TermForm.php, line 136

Class

TermForm
Base for handler for taxonomy term edit forms.

Namespace

Drupal\taxonomy

Code

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

  // Ensure numeric values.
  if ($form_state
    ->hasValue('weight') && !is_numeric($form_state
    ->getValue('weight'))) {
    $form_state
      ->setErrorByName('weight', $this
      ->t('Weight value must be numeric.'));
  }
}