Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
new_project
Project
Project
Details
Activity
Releases
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
Changes
1
Show 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,8 +8,8 @@ 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
(
in_array
(
'redaktory'
,
$account
->
getRoles
())){
if
(
$type
==
'editor'
&&
$op
==
'update'
)
{
//Узнать uid в поле ноды
$uid_role
=
$node
->
get
(
'field_role'
)
->
target_id
;
...
...
@@ -20,4 +20,36 @@ function role_node_access(\Drupal\node\NodeInterface $node, $op, \Drupal\Core\Se
}
}
}
// 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