Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
new_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
Telenkov Ruslan
new_project
Commits
38417bd2
Commit
38417bd2
authored
Jun 07, 2022
by
Telenkov Ruslan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
this is role task
parent
225992c2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
8 deletions
+40
-8
role.module
app/docroot/modules/custom/role/role.module
+40
-8
No files found.
app/docroot/modules/custom/role/role.module
View file @
38417bd2
...
...
@@ -8,16 +8,48 @@ use Drupal\node\NodeInterface;
function
role_node_access
(
\Drupal\node\NodeInterface
$node
,
$op
,
\Drupal\Core\Session\AccountInterface
$account
)
{
$type
=
$node
->
bundle
();
if
(
$account
->
id
()
!=
'1'
)
{
if
(
$type
==
'editor'
&&
$op
==
'update'
)
{
//Узнать uid в поле ноды
$uid_role
=
$node
->
get
(
'field_role'
)
->
target_id
;
// id текущего пользователя
$uid_now
=
$account
->
id
();
if
(
$uid_now
==
$uid_role
)
{
return
AccessResult
::
allowed
();
if
(
in_array
(
'redaktory'
,
$account
->
getRoles
())){
if
(
$type
==
'editor'
&&
$op
==
'update'
)
{
//Узнать uid в поле ноды
$uid_role
=
$node
->
get
(
'field_role'
)
->
target_id
;
// id текущего пользователя
$uid_now
=
$account
->
id
();
if
(
$uid_now
==
$uid_role
)
{
return
AccessResult
::
allowed
();
}
}
}
// if ($type == 'editor' && $op == 'create') {
//$a =1;
// }
}
/**
* Implements hook_form_alter().
*/
function
role_form_alter
(
&
$form
,
\Drupal\Core\Form\FormStateInterface
$form_state
,
$form_id
)
{
if
(
$form_id
==
'node_editor_edit_form'
)
{
$current_user
=
\Drupal
::
currentUser
();
if
(
in_array
(
'redaktory'
,
$current_user
->
getRoles
())){
$form
[
'field_role'
][
'#access'
]
=
false
;
}
}
if
(
$form_id
==
'node_editor_form'
)
{
$current_user
=
\Drupal
::
currentUser
();
if
(
in_array
(
'redaktory'
,
$current_user
->
getRoles
())){
$form
[
'field_role'
][
'#access'
]
=
false
;
}
}
}
function
role_node_insert
(
Drupal\Core\Entity\EntityInterface
$entity
)
{
$current_user
=
\Drupal
::
currentUser
();
// $entity->field_role->value = $current_user->id();
if
(
in_array
(
'redaktory'
,
$current_user
->
getRoles
()))
{
$entity
->
set
(
'field_role'
,
$current_user
->
id
());
$entity
->
save
();
}
}
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