You are here

public function XBBCodeTagForm::validateForm in Extensible BBCode 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

src/Form/XBBCodeTagForm.php, line 214
Contains \Drupal\xbbcode\Form\XBBCodeTagForm.

Class

XBBCodeTagForm
List custom tags and edit or delete them.

Namespace

Drupal\xbbcode\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $name = $form_state
    ->getValue('name');
  if (!preg_match('/^[a-z0-9]*$/i', $name)) {
    $form_state
      ->setErrorByName('name', $this
      ->t('The name must be alphanumeric.'));
  }
  if ($form['edit']['name']['#default_value'] != $name) {
    if (xbbcode_custom_tag_exists($name)) {
      $form_state
        ->setErrorByName('name', $this
        ->t('This name is already taken. Please delete or edit the old tag, or choose a different name.'));
    }
  }
}