You are here

function acl_node_access_explain in ACL 8

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

Implements hook_node_access_explain().

File

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

Code

function acl_node_access_explain($row) {
  static $interpretations = array();
  $database = \Drupal::database();
  if ($row->realm == 'acl') {
    if (!isset($interpretations[$row->gid])) {
      $acl = $database
        ->query("SELECT * FROM {acl} WHERE acl_id = :acl_id", [
        'acl_id' => $row->gid,
      ])
        ->fetchObject();
      $acl->tag = '?';
      if (!isset($acl->name)) {
        $acl->tag = $acl->figure;
      }
      elseif (!isset($acl->figure)) {
        $acl->tag = $acl->name;
      }
      else {
        $acl->tag = $acl->name . '-' . $acl->figure;
      }
      foreach (User::loadMultiple(acl_get_uids($row->gid)) as $account) {
        $account_names[] = _acl_format_account_name($account
          ->getAccountName());
      }
      if (!empty($account_names)) {
        $account_names = implode(', ', $account_names);
        $interpretations[$row->gid] = _acl_get_explanation("{$acl->module}/{$acl->tag}: {$account_names}", $acl->acl_id, $acl->module, $acl->name, $acl->figure, $account_names);
      }
      elseif ($row->gid == 0) {
        $result = $database
          ->query("SELECT an.acl_id, a.module, a.name FROM {acl_node} an JOIN {acl} a ON an.acl_id = a.acl_id LEFT JOIN {acl_user} au ON a.acl_id = au.acl_id WHERE an.nid = :nid AND au.uid IS NULL", [
          'nid' => $row->nid,
        ]);
        foreach ($result as $acl) {
          $rows[] = _acl_get_explanation("{$acl->acl_id}: {$acl->module}/{$acl->tag}", $acl->acl_id, $acl->module, $acl->name, $acl->figure);
        }
        if (!empty($rows)) {
          return implode('<br />', $rows);
        }
        return 'No access via ACL.';
      }
      else {
        $interpretations[$row->gid] = _acl_get_explanation("{$acl->module}/{$acl->tag}: no users!", $acl->acl_id, $acl->module, $acl->name, $acl->figure);
      }
    }
    return $interpretations[$row->gid];
  }
}