You are here

function rac_na_node_grants in Role Access Control 8

Implements hook_node_grants().

Returns any grants which may give the user permission to perform the requested op.

File

contrib/rac_na/rac_na.module, line 58
Module providing role base access for nodes.

Code

function rac_na_node_grants(AccountInterface $account, $op) {
  $grants = [];
  $access = $op === 'view' ? 1 : 2;
  $userRoles = _rac_get_account_roles($op, $account);
  foreach ($userRoles as $role) {
    $grants["rac_" . $role
      ->id()][] = $access;
  }
  if ($access === 1) {

    /*
     * For view access, check if the user has edit access. This is required if
     * the content is unpublishes, since the view grant records will not be
     * stored, but update grants view.
     */
    $update_grants = rac_na_node_grants($account, "update");
    if ($update_grants) {
      $grants = array_merge_recursive($grants, $update_grants);
    }
  }
  if (count($grants)) {
    return $grants;
  }
}