You are here

function simple_access_node_grants in Simple Access 8.3

Same name and namespace in other branches
  1. 5.2 simple_access.module \simple_access_node_grants()
  2. 5 simple_access.module \simple_access_node_grants()
  3. 6.2 simple_access.module \simple_access_node_grants()
  4. 7.2 simple_access.module \simple_access_node_grants()

Implements hook_node_grants().

File

./simple_access.module, line 176
Builds simple access definition for content access.

Code

function simple_access_node_grants(AccountInterface $account, $op) {
  $grants = [];
  $groups = SimpleAccessGroup::loadMultiple();
  $profiles = SimpleAccessProfile::loadMultiple();

  /** @var \Drupal\simple_access\Entity\SimpleAccessGroup $group */
  foreach ($groups as $group) {
    if ($grant = $group
      ->buildGrant($account, $op)) {
      $grants = array_merge_recursive($grants, $grant);
    }
  }

  /** @var \Drupal\simple_access\Entity\SimpleAccessProfile $profile */
  foreach ($profiles as $profile) {
    if ($grant = $profile
      ->buildGrant($account, $op)) {
      $grants = array_merge_recursive($grants, $grant);
    }
  }
  return $grants;
}