You are here

function book_access_node_access_explain in Book access 7.2

Same name and namespace in other branches
  1. 6.2 book_access.module \book_access_node_access_explain()
  2. 6 book_access.module \book_access_node_access_explain()
  3. 1.x book_access.module \book_access_node_access_explain()

Implements hook_node_access_explain().

hook_node_access_explain() is defined in devel_node_access.module, which helps you to figure out how node access works and what permissions are currently granted.

File

./book_access.module, line 1036
Allows to set the access control for book nodes on a per book basis. Based on forum_access.module and tac_lite.module.

Code

function book_access_node_access_explain($row) {
  static $roles = NULL;
  $result = array();
  if ($row->realm == 'book_access_author') {
    $result = array(
      t('Grants for book authors'),
    );
  }
  elseif ($row->realm == 'book_access_role') {
    if (!isset($roles)) {
      $roles = user_roles();
    }
    if (isset($roles[$row->gid])) {
      $result = array(
        t('Grants for users of role %role', array(
          '%role' => $roles[$row->gid],
        )),
      );
    }
    else {
      $result = array(
        t('Unknown group ID %gid', array(
          '%gid' => $row->gid,
        )),
      );
    }
  }
  elseif ($row->realm == 'book_access_user') {
    if ($user = user_load($row->gid)) {
      $result = array(
        t('Grants for user %username', array(
          '%username' => $user->name,
        )),
      );
    }
    else {
      $result = array(
        t('Unknown user ID %gid', array(
          '%gid' => $row->gid,
        )),
      );
    }
  }
  return $result;
}