Commit 38417bd2 authored by Telenkov Ruslan's avatar Telenkov Ruslan

this is role task

parent 225992c2
...@@ -8,8 +8,8 @@ use Drupal\node\NodeInterface; ...@@ -8,8 +8,8 @@ use Drupal\node\NodeInterface;
function role_node_access(\Drupal\node\NodeInterface $node, $op, \Drupal\Core\Session\AccountInterface $account) { function role_node_access(\Drupal\node\NodeInterface $node, $op, \Drupal\Core\Session\AccountInterface $account) {
$type = $node $type = $node
->bundle(); ->bundle();
if ($account->id() != '1') {
if (in_array('redaktory', $account->getRoles())){
if ($type == 'editor' && $op == 'update') { if ($type == 'editor' && $op == 'update') {
//Узнать uid в поле ноды //Узнать uid в поле ноды
$uid_role = $node->get('field_role')->target_id; $uid_role = $node->get('field_role')->target_id;
...@@ -20,4 +20,36 @@ function role_node_access(\Drupal\node\NodeInterface $node, $op, \Drupal\Core\Se ...@@ -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();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment