Skip to content
Snippets Groups Projects
Commit 5a7e9dea authored by aaron.ferris's avatar aaron.ferris Committed by Julian Pustkuchen
Browse files

Issue #3184073 by aaron.ferris, grasmash, Anybody: Add ability to disable redirects for admins

parent a42b1a69
No related branches found
No related tags found
1 merge request!8Issue: #3184073: add an option to disable for administrators
......@@ -3,6 +3,7 @@
namespace Drupal\front_page\EventSubscriber;
use Drupal\Core\Url;
use Drupal\user\Entity\User;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
......@@ -50,6 +51,12 @@ class FrontPageSubscriber implements EventSubscriberInterface {
$config = \Drupal::configFactory()->get('front_page.settings');
$current_weight = NULL;
/** @var \Drupal\user\Entity\User $user */
$user = User::load(\Drupal::currentUser()->id());
if ($user->hasRole('administrator') && $config->get('disable_for_administrators')) {
return;
}
foreach ($roles as $role) {
$role_config = $config->get('roles.' . $role);
if ((isset($role_config['enabled']) && $role_config['enabled'] == TRUE)
......
......@@ -40,6 +40,13 @@ class FrontPageSettingsForm extends ConfigFormBase {
'#default_value' => $config->get('enabled') ?: FALSE,
];
$form['disable_for_administrators'] = [
'#type' => 'checkbox',
'#title' => $this->t('Disable front page redirects for the administrator role.'),
'#description' => $this->t('If checked, admin users will never be redirected, even if the authenticated user role has a redirect enabled.'),
'#default_value' => $config->get('disable_for_administrators') ?: FALSE,
];
// Load any existing settings and build the by redirect by role form.
$form['roles'] = [
'#tree' => TRUE,
......@@ -113,6 +120,7 @@ class FrontPageSettingsForm extends ConfigFormBase {
// Set if all config are enabled or not.
$config->set('enabled', $form_state->getValue('front_page_enable'));
$config->set('disable_for_administrators', $form_state->getValue('disable_for_administrators'));
//Set config by role.
$rolesList = $form_state->getUserInput()['roles'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment