You are here

public static function BookAccess::setDefaultForRole in Book access 7.2

Parameters

$rid: The role id to set the default for.

$rname: The optional name of the role. If specified, this saves a database trip, as otherwise this method uses $rid to look up the name.

Based on the role name, this initializes the default grants for the role id. This is only intended to be used during hook_init() or when creating a brand new role.

2 calls to BookAccess::setDefaultForRole()
book_access_init in ./book_access.module
Implements hook_init().
book_access_user_role_insert in ./book_access.module
Implements hook_user_role_insert().

File

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

Class

BookAccess
@file

Code

public static function setDefaultForRole($rid, $rname = NULL) {
  if (!$rname) {
    $role = user_role_load($rid);
    if ($role === FALSE) {
      drupal_set_message(t("Could not set default book_access grants for role: @rid, role not found", array(
        '@rid' => $rid,
      )), "error");
      return;
    }
    $rname = $role->rid;
  }
  if ($rname == 'administrator') {
    $defaultToUse = self::grantIDs();
  }
  else {
    $defaultToUse = self::defaultGrants();
  }
  if (variable_get("book_access_default_role_{$rid}_access") === NULL) {
    variable_set("book_access_default_role_{$rid}_access", $defaultToUse);
  }
}