Skip to content
Snippets Groups Projects

3349124-redirect-after-registration/password-reset:Created the functionality of User Redirect After Registration/Password Reset.

Files
4
@@ -123,6 +123,20 @@ class UserRedirectSettingsForm extends ConfigFormBase {
],
];
// Adding new fields for registration and password reset redirection URLs.
$form['registration_redirect'] = [
'#type' => 'textfield',
'#title' => $this->t('Registration Redirect URL (For all roles).'),
'#description' => $this->t('Enter the URL where users should be redirected after registration.'),
'#default_value' => $config->get('registration_redirect'),
];
$form['password_reset_redirect'] = [
'#type' => 'textfield',
'#title' => $this->t('Password Reset Redirect URL (For all roles).'),
'#description' => $this->t('Enter the URL where users should be redirected after password reset.'),
'#default_value' => $config->get('password_reset_redirect'),
];
// Login & logout draggable form.
foreach ($users_roles as $role_id => $role_name) {
$data = $config->get('login.' . $role_id);
@@ -199,8 +213,24 @@ class UserRedirectSettingsForm extends ConfigFormBase {
$login = $form_state->getValue('login');
$logout = $form_state->getValue('logout');
$register_redirect = $form_state->getValue('registration_redirect');
$password_redirect = $form_state->getValue('password_reset_redirect');
$users_roles = $this->getUserRoles();
if (!empty($password_redirect) && !$this->pathValidator->isValid($password_redirect)) {
if (!UrlHelper::isValid($password_redirect, TRUE) && !UrlHelper::isExternal($password_redirect)) {
$form_state->setErrorByName('password_reset_redirect', $this->t('<strong>Password Reset Redirect URL:</strong> Redirect URL is invalid.'));
}
}
if (!empty($register_redirect) && !$this->pathValidator->isValid($register_redirect)) {
if (!UrlHelper::isValid($register_redirect, TRUE) && !UrlHelper::isExternal($register_redirect)) {
$form_state->setErrorByName('registration_redirect', $this->t('<strong>Password Reset Redirect URL:</strong> Redirect URL is invalid.'));
}
}
foreach ($users_roles as $role_id => $role_name) {
$login_url = $login[$role_id]['redirect_url'];
$logout_url = $logout[$role_id]['redirect_url'];
@@ -227,6 +257,8 @@ class UserRedirectSettingsForm extends ConfigFormBase {
$this->config(static::CONFIG_SETTINGS)
->set('login', $form_state->getValue('login'))
->set('logout', $form_state->getValue('logout'))
->set('registration_redirect', $form_state->getValue('registration_redirect'))
->set('password_reset_redirect', $form_state->getValue('password_reset_redirect'))
->set('ignore', array_filter(explode("\r\n", $form_state->getValue('ignore'))))
->set('ignore_for', $form_state->getValue('ignore_for'))
->save();
Loading