private function IpBanAdmin::iPBanValidatePaths in IP Ban 8
Custom validation function for path redirects.
Custom validation function for the path to redirect to for banned or read-only users. Here we simply ensure the path specified exists, and if not, display a form error.
1 call to IpBanAdmin::iPBanValidatePaths()
- IpBanAdmin::validateForm in src/
Form/ IpBanAdmin.php - Form validation handler.
File
- src/
Form/ IpBanAdmin.php, line 184
Class
Namespace
Drupal\ip_ban\FormCode
private function iPBanValidatePaths($form_element, $form_value, array &$form, FormStateInterface $form_state) {
// An empty path is valid here because the path is not a required field.
if (!empty($form_value)) {
$normal_path = \Drupal::service('path_alias.manager')
->getPathByAlias($form_value);
if (!\Drupal::service('path.validator')
->isValid($normal_path)) {
$form_state
->setErrorByName($form_element, $this
->t('The path entered does not exist or you do not have permission to access it.'));
}
// Check if the first character entered is a
if ($normal_path[0] != "/") {
$form_state
->setErrorByName($form_element, $this
->t('The path must start with a forward slash (/).'));
}
}
}