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
736dc507
Commit
736dc507
authored
4 years ago
by
Eric Bremner
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-3921: adding submit function handling for content access form
parent
d89c1826
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Form/UwContentAccessForm.php
+70
-13
70 additions, 13 deletions
src/Form/UwContentAccessForm.php
with
70 additions
and
13 deletions
src/Form/UwContentAccessForm.php
+
70
−
13
View file @
736dc507
...
...
@@ -129,8 +129,7 @@ class UwContentAccessForm extends FormBase {
foreach
(
$uw_permission
as
$perm
=>
$uw_permission_roles
)
{
// Set the row name to be use for this table (role-permission_name).
$row_name
=
strtolower
(
str_replace
(
' '
,
'_'
,
$feature
));
$row_name
.
=
'-'
.
strtolower
(
str_replace
(
' '
,
'_'
,
$perm
));
$row_name
=
$feature
.
'-'
.
$perm
;
// If we are on the first of the row, setup the description.
if
(
$row_count
==
0
)
{
...
...
@@ -175,9 +174,78 @@ class UwContentAccessForm extends FormBase {
}
}
$form
[
'actions'
][
'#type'
]
=
'actions'
;
$form
[
'actions'
][
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#value'
=>
$this
->
t
(
'Submit'
),
'#button_type'
=>
'primary'
,
);
return
$form
;
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
// The permissions array that was submitted in the form.
$submitted_permissions
=
$form_state
->
getValue
(
'permissions'
);
// The array of uw permissions.
$uw_permissions
=
$this
->
uw_get_permissions_array
();
// The array of uw roles.
$uw_roles
=
$this
->
uw_get_uw_roles_content_access_form
();
// Step through each role and store the role object.
foreach
(
$uw_roles
as
$uw_role
)
{
// Store the role object.
$uw_role_objects
[
$uw_role
[
'name'
]]
=
\Drupal\user\Entity\Role
::
load
(
$uw_role
[
'id'
]);
}
// Step through each of the submitted permissions to grant or revoke it for the role.
// Step through each of the permissions array to get the row name (role-permission).
foreach
(
$submitted_permissions
as
$row_name
=>
$submitted_permission
)
{
// Step through each of the role-permissions to revoke or grant.
foreach
(
$submitted_permission
as
$uw_role_name
=>
$permission_value
)
{
// Break up the row name from role-permission into array.
// 0th element is role.
// 1st element is permission.
$perm_names
=
explode
(
'-'
,
$row_name
);
// Get the list of permissions to revoke/grant from the uw_permissions array.
$uw_perms
=
$uw_permissions
[
$perm_names
[
0
]][
$perm_names
[
1
]][
$uw_role_name
];
// If the checkbox was selected on the form grant the permissions that is
// in the uw_permissions array for that role.
if
(
$permission_value
)
{
// Step through each of the permissions for that role and grant the permission.
foreach
(
$uw_perms
as
$uw_perm
)
{
// Grant the permission for the specified role.
$uw_role_objects
[
$uw_role_name
]
->
grantPermission
(
$uw_perm
);
}
}
// If the checkbox was not selected on the form revoke the permissions that is
// in the uw_permissions array for that role.
else
{
// Step through each of the permissions for that role and revoke the permission.
foreach
(
$uw_perms
as
$uw_perm
)
{
// Revoke the permission for the specified role.
$uw_role_objects
[
$uw_role_name
]
->
revokePermission
(
$uw_perm
);
}
}
}
}
}
/**
* Get UW roles that are going to be used for the form.
*
...
...
@@ -331,15 +399,4 @@ class UwContentAccessForm extends FormBase {
return
$uw_permissions
;
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
// drupal_set_message($this->t('@can_name ,Your application is being submitted!', array('@can_name' => $form_state->getValue('candidate_name'))));
foreach
(
$form_state
->
getValues
()
as
$key
=>
$value
)
{
drupal_set_message
(
$key
.
': '
.
$value
);
}
}
}
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