You are here

function nodeaccess_node_grants in Nodeaccess 8

Same name and namespace in other branches
  1. 8.2 nodeaccess.module \nodeaccess_node_grants()
  2. 5 nodeaccess.module \nodeaccess_node_grants()
  3. 6.2 nodeaccess.module \nodeaccess_node_grants()
  4. 6 nodeaccess.module \nodeaccess_node_grants()
  5. 7 nodeaccess.module \nodeaccess_node_grants()

Implements hook_node_grants().

File

./nodeaccess.module, line 123
Control access to site content based on the users and roles.

Code

function nodeaccess_node_grants(AccountInterface $account, $op) {
  $config = \Drupal::configFactory()
    ->get('nodeaccess.settings');
  $role_map = $config
    ->get('role_map');
  $roles = $account
    ->getRoles();
  $rids = [];
  foreach ($roles as $role) {
    $rids[] = $role_map[$role];
  }
  return [
    'nodeaccess_rid' => $rids,
    'nodeaccess_uid' => [
      $account
        ->id(),
    ],
    'nodeaccess_author' => [
      $account
        ->id(),
    ],
  ];
}