You are here

function acl_node_access_records in ACL 8

Same name and namespace in other branches
  1. 5 acl.module \acl_node_access_records()
  2. 6 acl.module \acl_node_access_records()
  3. 7 acl.module \acl_node_access_records()

Implements hook_node_access_records().

File

./acl.module, line 308
An API module providing by-user access control lists.

Code

function acl_node_access_records(NodeInterface $node) {
  if (!$node
    ->id()) {
    return;
  }
  $result = \Drupal::database()
    ->query("SELECT n.*, 'acl' AS realm, n.acl_id AS gid, a.module FROM {acl_node} n INNER JOIN {acl} a ON n.acl_id = a.acl_id WHERE nid = :nid", [
    'nid' => $node
      ->id(),
  ], [
    'fetch' => PDO::FETCH_ASSOC,
  ]);
  $grants = array();
  foreach ($result as $grant) {
    if (\Drupal::moduleHandler()
      ->invoke($grant['module'], 'enabled')) {
      if (acl_has_users($grant['gid'])) {
        $grants[] = $grant;
      }
      else {

        //just deny access
        $grants[] = [
          'realm' => 'acl',
          'gid' => $grant['gid'],
          'grant_view' => 0,
          'grant_update' => 0,
          'grant_delete' => 0,
          'priority' => $grant['priority'],
        ];
      }
    }
  }
  return $grants;
}