You are here

function entity_access_by_field_node_grants in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()
  2. 8.2 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()
  3. 8.3 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()
  4. 8.4 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()
  5. 8.5 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()
  6. 8.6 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()
  7. 8.7 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()
  8. 8.8 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()
  9. 10.3.x modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()
  10. 10.0.x modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()
  11. 10.1.x modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()
  12. 10.2.x modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_node_grants()

Implements hook_node_grants().

File

modules/custom/entity_access_by_field/entity_access_by_field.module, line 36
Entity Access By Field module file.

Code

function entity_access_by_field_node_grants(AccountInterface $account, $op) {
  $grants = [];
  if ($op === 'view') {

    // @TODO Check performance hit, this is not cached.
    $entityAccessPermissions = \Drupal::getContainer()
      ->get('entity_access_by_field.permissions');
    $permissions = $entityAccessPermissions
      ->getRealmWithPermission();
    if (!empty($permissions)) {
      foreach ($permissions as $realm => $permission) {
        if ($account
          ->hasPermission($permission)) {
          $grants[$realm][] = ENTITY_ACCESS_BY_FIELD_ALLOWED_REALM;
        }
        $grants[$realm . '_author'] = [
          $account
            ->id(),
        ];
      }
    }
  }
  return $grants;
}