Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
front
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
front
Commits
5a7e9dea
Commit
5a7e9dea
authored
1 year ago
by
aaron.ferris
Committed by
Julian Pustkuchen
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
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
!8
Issue: #3184073: add an option to disable for administrators
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/EventSubscriber/FrontPageSubscriber.php
+7
-0
7 additions, 0 deletions
src/EventSubscriber/FrontPageSubscriber.php
src/Form/FrontPageSettingsForm.php
+8
-0
8 additions, 0 deletions
src/Form/FrontPageSettingsForm.php
with
15 additions
and
0 deletions
src/EventSubscriber/FrontPageSubscriber.php
+
7
−
0
View file @
5a7e9dea
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
src/Form/FrontPageSettingsForm.php
+
8
−
0
View file @
5a7e9dea
...
...
@@ -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'
];
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment