You are here

function book_access_node_insert in Book access 7.2

Same name and namespace in other branches
  1. 1.x book_access.module \book_access_node_insert()

Implements hook_node_insert().

Specifically targets creation of book nodes to set some default permissions

File

./book_access.module, line 850
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_insert($node) {
  if (isset($node->book['bid']) && $node->book['bid'] && $node->nid == $node->book['bid']) {
    BookAccess::setAuthorGrants($node->book['bid'], $node->uid, drupal_map_assoc($node->uid == 0 ? BookAccess::defaultGrants() : variable_get("book_access_default_author_access")));
    $roles = user_roles();
    $rids = array_keys($roles);
    foreach ($rids as $rid) {
      $roleDefaults = variable_get("book_access_default_role_{$rid}_access", array());
      foreach ($roleDefaults as $default) {
        $roleGrants[$default][$rid] = TRUE;
      }
    }
    BookAccess::setRoleGrants($node->book['bid'], $rids, $roleGrants);
  }
}