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
c2dd9789
Commit
c2dd9789
authored
4 years ago
by
Eric Bremner
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-3921: adding class to handle UW permissions
parent
8ccc7cac
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/UwPermissions/UwPermissions.php
+206
-0
206 additions, 0 deletions
src/UwPermissions/UwPermissions.php
with
206 additions
and
0 deletions
src/UwPermissions/UwPermissions.php
0 → 100644
+
206
−
0
View file @
c2dd9789
<?php
namespace
Drupal\uw_cfg_common\UwPermissions
;
/**
* Class UwPermissions.
*/
class
UwPermissions
{
/**
* Get UW roles.
*
* @return array
* An array of the UW roles to be used on this form.
*/
public
static
function
uw_get_roles
():
array
{
// UW site manager role.
$uw_roles
[
'Site manager'
]
=
[
'name'
=>
'Site manager'
,
'id'
=>
'uw_role_site_manager'
,
'object'
=>
\Drupal\user\Entity\Role
::
load
(
'uw_role_site_manager'
),
];
// UW content editor role.
$uw_roles
[
'Content editor'
]
=
[
'name'
=>
'Content editor'
,
'id'
=>
'uw_role_content_editor'
,
'object'
=>
\Drupal\user\Entity\Role
::
load
(
'uw_role_content_editor'
),
];
// UW content author role.
$uw_roles
[
'Content author'
]
=
[
'name'
=>
'Content author'
,
'id'
=>
'uw_role_content_author'
,
'object'
=>
\Drupal\user\Entity\Role
::
load
(
'uw_role_content_author'
),
];
return
$uw_roles
;
}
/**
* Get Uw content permissions array.
*
* @return array
* The array of all permissions for uw content access form.
*/
public
static
function
uw_get_permissions_array
():
array
{
$uw_permissions
=
[
// Blog permissions.
'Blog'
=>
[
'Use content type'
=>
UwPermissions
::
uw_build_role_permissions_list_content_type
(
'uw_ct_blog'
),
],
// Event permissions.
'Event'
=>
[
'Use content type'
=>
UwPermissions
::
uw_build_role_permissions_list_content_type
(
'uw_ct_event'
),
'Create/Edit tags'
=>
UwPermissions
::
uw_build_role_permissions_list_taxonomy_term
(
'uw_tax_event_tags'
,
[
'create'
,
'edit'
]),
'Delete tags'
=>
UwPermissions
::
uw_build_role_permissions_list_taxonomy_term
(
'uw_tax_event_tags'
,
[
'delete'
]),
'Create/Edit types'
=>
UwPermissions
::
uw_build_role_permissions_list_taxonomy_term
(
'uw_tax_event_type'
,
[
'create'
,
'edit'
]),
'Delete types'
=>
UwPermissions
::
uw_build_role_permissions_list_taxonomy_term
(
'uw_tax_event_type'
,
[
'delete'
]),
],
// News permissions.
'News'
=>
[
'Use content type'
=>
UwPermissions
::
uw_build_role_permissions_list_content_type
(
'uw_ct_news_item'
),
],
// Site footer permissions.
'Site footer'
=>
[
'Use content type'
=>
UwPermissions
::
uw_build_role_permissions_list_content_type
(
'uw_ct_site_footer'
),
],
// Special alert permissions.
'Special alert'
=>
[
'Use content type'
=>
UwPermissions
::
uw_build_role_permissions_list_custom
(
'administer special alert'
),
],
// Web page permissions.
'Web page'
=>
[
'Use content type'
=>
UwPermissions
::
uw_build_role_permissions_list_content_type
(
'uw_ct_web_page'
),
],
];
return
$uw_permissions
;
}
/**
* Build uw role permissions list for content types.
*
* @param string $ct_name
* The machine name of the content type.
* @return array
* An array of the uw permissions.
*/
public
static
function
uw_build_role_permissions_list_content_type
(
string
$ct_name
):
array
{
// Build the permissions list for the content type.
$content_type_permissions_list
=
[
'Site manager'
=>
[
'create '
.
$ct_name
.
' content'
,
'delete any '
.
$ct_name
.
' content'
,
'delete own '
.
$ct_name
.
' content'
,
'edit any '
.
$ct_name
.
' content'
,
'edit own '
.
$ct_name
.
' content'
,
'revert '
.
$ct_name
.
' revisions'
,
'view '
.
$ct_name
.
' revisions'
,
],
'Content editor'
=>
[
'create '
.
$ct_name
.
' content'
,
'edit any '
.
$ct_name
.
' content'
,
'edit own '
.
$ct_name
.
' content'
,
'revert '
.
$ct_name
.
' revisions'
,
'view '
.
$ct_name
.
' revisions'
,
],
'Content author'
=>
[
'create '
.
$ct_name
.
' content'
,
'edit any '
.
$ct_name
.
' content'
,
'edit own '
.
$ct_name
.
' content'
,
'revert '
.
$ct_name
.
' revisions'
,
'view '
.
$ct_name
.
' revisions'
,
],
];
return
$content_type_permissions_list
;
}
/**
* Build role permissions list for a custom permission.
*
* @param string $permission_name
* The machine name of the taxonomy term.
* @return array
* An array of the uw permissions.
*/
public
static
function
uw_build_role_permissions_list_custom
(
string
$permission_name
):
array
{
// The roles used for the uw permissions.
$uw_roles
=
UwPermissions
::
uw_get_roles
();
// Step through each role and add permission.
foreach
(
$uw_roles
as
$uw_role
)
{
// Set the permission.
$uw_permissions
[
$uw_role
[
'name'
]][]
=
[
$permission_name
,
];
}
return
$uw_permissions
;
}
/**
* Build role permissions list for taxonomy terms.
*
* @param string $tax_name
* The machine name of the taxonomy term.
* @param array $permission_types
* The list of permissions for the taxonomy term (create, edit and/or delete).
* @return array
* An array of the uw permissions.
*/
public
static
function
uw_build_role_permissions_list_taxonomy_term
(
string
$tax_name
,
array
$permission_types
):
array
{
// The roles used for the uw permissions.
$uw_roles
=
UWPermissions
::
uw_get_roles
();
// Step through each of the uw roles and setup list of permissions.
foreach
(
$uw_roles
as
$uw_role
)
{
// Step through each permission types and setup list of permissions.
foreach
(
$permission_types
as
$permission_type
)
{
// Set the permission.
$uw_permissions
[
$uw_role
[
'name'
]][]
=
$permission_type
.
' terms in '
.
$tax_name
;
}
}
return
$uw_permissions
;
}
/**
* Save UW permissions.
*
* @parm array $uw_roles
* The array of roles to be saved.
*/
public
static
function
uw_save_permissions
(
array
$uw_roles
)
{
// Step through each of the roles and save the role object,
// so that the permissions get saved.
foreach
(
$uw_roles
as
$uw_role
)
{
// Save the role object.
$uw_role
[
'object'
]
->
save
();
}
}
}
\ No newline at end of file
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