function r4032login_form_system_site_information_settings_validate in Redirect 403 to User Login 2.x
Same name and namespace in other branches
- 8 r4032login.module \r4032login_form_system_site_information_settings_validate()
Form validation handler for system_site_information_settings().
See also
r4032login_form_system_site_information_settings_alter()
1 string reference to 'r4032login_form_system_site_information_settings_validate'
File
- ./
r4032login.module, line 136 - Redirect denied pages to the user login form.
Code
function r4032login_form_system_site_information_settings_validate($form, FormStateInterface $form_state) {
$path_validator = \Drupal::pathValidator();
if (!$form_state
->isValueEmpty('r4032login_redirect_authenticated_users_to') && !$path_validator
->isValid($form_state
->getValue('r4032login_redirect_authenticated_users_to'))) {
$form_state
->setErrorByName('r4032login_redirect_authenticated_users_to', t("The redirect authenticated users path '%path' is either invalid or you do not have access to it.", [
'%path' => $form_state
->getValue('r4032login_redirect_authenticated_users_to'),
]));
}
if (!$form_state
->isValueEmpty('r4032login_user_login_path')) {
$r4032loginUserLoginPath = $form_state
->getValue('r4032login_user_login_path');
// If Rename Admin Paths is present, replace its path by "user"
// for validation so we can validate the path as usual.
$moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler
->moduleExists('rename_admin_paths') && ($configFactory = \Drupal::service('config.factory')) && ($renameAdminPathsSettings = $configFactory
->get('rename_admin_paths.settings')
->getRawData()) && !empty($renameAdminPathsSettings['user_path']) && !empty($renameAdminPathsSettings['user_path_value'])) {
$r4032loginUserLoginPath = str_replace($renameAdminPathsSettings['user_path_value'], 'user', $r4032loginUserLoginPath);
}
// Check the path validity
// and whether the anonymous user can access the entered path.
if (!UrlHelper::isExternal($r4032loginUserLoginPath) && (!$path_validator
->getUrlIfValidWithoutAccessCheck($r4032loginUserLoginPath) || !($url = Url::fromUserInput($r4032loginUserLoginPath)) || !$url
->access(User::getAnonymousUser()))) {
$form_state
->setErrorByName('r4032login_user_login_path', t("The user login form path '%path' is either invalid or a logged out user does not have access to it.", [
'%path' => $form_state
->getValue('r4032login_user_login_path'),
]));
}
}
}