You are here

public static function BookAccess::writeGrantRecords in Book access 7.2

Same name and namespace in other branches
  1. 6.2 book_access.module \BookAccess::writeGrantRecords()
2 calls to BookAccess::writeGrantRecords()
book_access_edit_form_submit in ./book_access.module
Form submission callback for node_form(), and book_outline_form().
book_access_outline_form_submit in ./book_access.module
Form submission callback for book_outline_form().

File

./book_access.module, line 795
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 writeGrantRecords($node, array $types = array(
  'author',
  'role',
  'user',
)) {
  if (!empty($node->nid) && !empty($node->book['bid'])) {
    foreach ($types as $type) {
      switch ($type) {
        case 'author':
        case 'role':
        case 'user':
          $table = "book_access_{$type}";
          break;
        default:
          $table = '';
      }
      if ($table && ($grants = self::getGrantRecords($node->book['bid'], array(
        $type,
      )))) {
        node_access_write_grants($node, $grants, $table, TRUE);
      }
    }
  }
}