You are here

public function RenameAdminPathsSettingsForm::validate in Rename Admin Paths 8.2

Form element validation handler.

Parameters

array $element:

FormStateInterface $formState:

File

src/Form/RenameAdminPathsSettingsForm.php, line 133

Class

RenameAdminPathsSettingsForm

Namespace

Drupal\rename_admin_paths\Form

Code

public function validate(&$element, FormStateInterface $formState) {
  if (empty($element['#value'])) {
    $formState
      ->setError($element, $this
      ->t('Path replacement value must contain a value.'));
  }
  elseif (!RenameAdminPathsValidator::isValidPath($element['#value'])) {
    $formState
      ->setError($element, $this
      ->t('Path replacement value must contain only letters, numbers, hyphens and underscores.'));
  }
  elseif (RenameAdminPathsValidator::isDefaultPath($element['#value'])) {
    $formState
      ->setError($element, sprintf($this
      ->t('Renaming to a default name (%s) is not allowed.'), implode(', ', RenameAdminPathsEventSubscriber::ADMIN_PATHS)));
  }
}