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

this is role task

parent 225992c2
......@@ -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();
}
}
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