Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_cfg_common
Commits
830539ba
Commit
830539ba
authored
3 years ago
by
Liam Morland
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5174: Show login/logout message on Webform access denied page
parent
dfb3ddd2
No related branches found
No related tags found
1 merge request
!161
ISTWCMS-4907: Implement access control for Webforms
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
uw_cfg_common.module
+44
-0
44 additions, 0 deletions
uw_cfg_common.module
with
44 additions
and
0 deletions
uw_cfg_common.module
+
44
−
0
View file @
830539ba
...
@@ -377,6 +377,10 @@ function uw_cfg_common_webform_create(WebformInterface $webform) {
...
@@ -377,6 +377,10 @@ function uw_cfg_common_webform_create(WebformInterface $webform) {
// Submission purge settings. Set the default to purge drafts after 28 days.
// Submission purge settings. Set the default to purge drafts after 28 days.
$webform
->
setSetting
(
'purge'
,
WebformSubmissionStorageInterface
::
PURGE_DRAFT
);
$webform
->
setSetting
(
'purge'
,
WebformSubmissionStorageInterface
::
PURGE_DRAFT
);
$webform
->
setSetting
(
'purge_days'
,
28
);
$webform
->
setSetting
(
'purge_days'
,
28
);
// Set so that uw_cfg_common_webform_build_access_denied_alter() will run.
// This value is tested for in Webform::preRenderWebformElement().
$webform
->
setSetting
(
'form_access_denied'
,
'page'
);
}
}
/**
/**
...
@@ -835,3 +839,43 @@ function uw_cfg_common_get_user_ad_groups(): ?array {
...
@@ -835,3 +839,43 @@ function uw_cfg_common_get_user_ad_groups(): ?array {
$attributes
=
\Drupal
::
service
(
'simplesamlphp_auth.manager'
)
->
getAttributes
();
$attributes
=
\Drupal
::
service
(
'simplesamlphp_auth.manager'
)
->
getAttributes
();
return
$attributes
[
'http://schemas.xmlsoap.org/claims/Group'
]
??
NULL
;
return
$attributes
[
'http://schemas.xmlsoap.org/claims/Group'
]
??
NULL
;
}
}
/**
* Implements hook_webform_build_access_denied_alter().
*
* Custom access denied messages with login/logout links.
*/
function
uw_cfg_common_webform_build_access_denied_alter
(
array
&
$build
,
WebformInterface
$webform
):
void
{
$message
=
NULL
;
switch
(
$webform
->
getThirdPartySetting
(
'uw_cfg_common'
,
'access_control_method'
))
{
case
'auth'
:
case
'group'
:
case
'user'
:
// If authenticated access and anonymous user, login.
if
(
\Drupal
::
currentUser
()
->
isAnonymous
())
{
$route
=
'user.login'
;
$message
=
'You must <a href="@url">login to view this form</a>.'
;
}
break
;
case
'anon'
:
// If anonymous access and authenticated user, logout.
if
(
\Drupal
::
currentUser
()
->
isAuthenticated
())
{
$route
=
'user.logout'
;
$message
=
'This form must be completed anonymously. You must <a href="@url">logout to view this form</a>.'
;
}
break
;
}
// Set a custom message only if a message has been chosen above.
if
(
$message
)
{
$options
=
[
'query'
=>
\Drupal
::
destination
()
->
getAsArray
()];
$url
=
Url
::
fromRoute
(
$route
,
[],
$options
);
// phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString
$message
=
'<p>'
.
t
(
$message
,
[
'@url'
=>
$url
->
toString
()])
.
'</p>'
;
$build
[
'message'
]
=
[
'#markup'
=>
$message
,
];
}
}
This diff is collapsed.
Click to expand it.
Liam Morland
@lkmorlan
mentioned in commit
4eb7d0c9
·
3 years ago
mentioned in commit
4eb7d0c9
mentioned in commit 4eb7d0c9d8a58b60f7ecd2c8526cd7c0371b2a83
Toggle commit list
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