Nodeaccess does not implement hook_node_access_explain()

Created on 18 June 2015, over 10 years ago
Updated 25 September 2025, 11 days ago

The Devel module has a really nice Node Access block that displays a table containing all the users, roles and permissions that apply to all node content on a page. However, it displays the numeric user ID and role ID rather than the username or role name. There is a column named "explained" however, that can be used to provide a more useful explanation of what the permissions mean. This column is populated from content returned by hook_node_access_explain(). Nodeaccess doesn't implement this hook, but I think it would be great if it did. I've added the following code to our Drupal 7 site running Nodeaccess 7.x-1.4 to implement this hook. It works great for us, so I though I'd contribute it back. I think it would make a great addition to a future version of Nodeaccess, but feel free to do with it what you like

/**
 * Implements hook_node_access_explain().
 */
function nodeaccess_node_access_explain($row) {

  $explain = '';

  if (($row->realm == 'nodeaccess_author') || ($row->realm == 'nodeaccess_rid')) {
    if ($row->realm == 'nodeaccess_author') {
      $account = user_load($row->gid);
      $explain = 'User ' . drupal_placeholder($account->name);
    } else {
      $role = user_role_load($row->gid);
      $explain = 'Role ' . drupal_placeholder($role->name);
    }

    $permissions = array();
    if ($row->grant_view) {
      $permissions[] = 'View';
    }
    if ($row->grant_update) {
      $permissions[] = 'Update';
    }
    if ($row->grant_delete) {
      $permissions[] = 'Delete';
    }

    if (empty($permissions)) {
      $explain .= ' has no access';
    } else {
      $explain .= ' has ' . implode(', ', $permissions) . ' access';
    }
  }

  return $explain;
}
Feature request
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

🇨🇦Canada g011um Saskatoon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024