Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Gorodkov Denis
Project
Commits
1e886dda
Commit
1e886dda
authored
Jun 20, 2022
by
Gorodkov Denis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor role editor
parent
50f4eed6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
role_editor.info.yml
app/docroot/modules/custom/role_editor/role_editor.info.yml
+7
-0
role_editor.module
app/docroot/modules/custom/role_editor/role_editor.module
+57
-0
No files found.
app/docroot/modules/custom/role_editor/role_editor.info.yml
0 → 100644
View file @
1e886dda
name
:
Role editor
description
:
Custom task
package
:
Tasks
type
:
module
core
:
8.x
core_version_requirement
:
^8 || ^9
app/docroot/modules/custom/role_editor/role_editor.module
0 → 100644
View file @
1e886dda
<?php
use
Drupal\Core\Access\AccessResult
;
/**
* Implements hook_ENTITY_TYPE_access()
*/
function
role_editor_node_access
(
\Drupal\Core\Entity\EntityInterface
$node
,
$operation
,
\Drupal\Core\Session\AccountInterface
$account
)
{
$user_roles
=
$account
->
getRoles
();
$isRedactor
=
false
;
foreach
(
$user_roles
as
$role
)
{
if
(
$role
==
'redactor'
)
{
$isRedactor
=
true
;
}
}
if
(
$operation
==
'delete'
)
{
if
(
$isRedactor
)
{
return
AccessResult
::
forbidden
();
}
}
if
(
$operation
==
'update'
)
{
if
(
$node
->
hasField
(
'field_editor'
))
{
$allow_redactors
=
$node
->
get
(
'field_editor'
)
->
referencedEntities
();
if
(
$isRedactor
)
{
foreach
(
$allow_redactors
as
$allow_redactor
)
{
if
(
$allow_redactor
->
id
()
==
$account
->
id
())
{
return
AccessResult
::
neutral
();
}
else
{
return
AccessResult
::
forbidden
();
}
}
}
}
}
}
/**
* Implements hook_node_insert()
*/
function
role_editor_node_insert
(
Drupal\Core\Entity\EntityInterface
$node
)
{
$user
=
Drupal
::
currentUser
();
$user_roles
=
$user
->
getRoles
();
$isRedactor
=
false
;
foreach
(
$user_roles
as
$role
)
{
if
(
$role
==
'redactor'
)
{
$isRedactor
=
true
;
}
}
if
(
$isRedactor
)
{
if
(
$node
->
hasField
(
'field_editor'
))
{
$node
->
field_editor
[]
=
$user
->
id
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment