You are here

public function AddFolderForm::validateForm in Taxonomy File Tree 8

Same name and namespace in other branches
  1. 3.x src/Form/AddFolderForm.php \Drupal\tft\Form\AddFolderForm::validateForm()

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/AddFolderForm.php, line 58

Class

AddFolderForm
Add a term form.

Namespace

Drupal\tft\Form

Code

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

  // If the user can only add terms to an Group.
  if (!$this
    ->currentUser()
    ->hasPermission(TFT_ADD_TERMS)) {
    if (!_tft_term_access($form_state
      ->getValue('parent'))) {
      $form_state
        ->setErrorByName('name');
      $this
        ->messenger()
        ->addMessage($this
        ->t("You must select a parent folder that is part of a group you're a member of."), 'error');
    }
  }

  // Check for forbidden characters.
  if (strpos($form_state
    ->getValue('name'), ',') !== FALSE || strpos($form_state
    ->getValue('name'), '+') !== FALSE) {
    $form_state
      ->setErrorByName('name', $this
      ->t("The following characters are not allowed: ',' (comma) and +"));
  }
}