You are here

public function CourseObjectBook::save in Course 7

Same name and namespace in other branches
  1. 7.2 modules/course_book/course_book.classes.inc \CourseObjectBook::save()

Override of CourseObjectNode::save()

We have to remove the stock "view" content access permissions on Books, if node_access_book is enabled. Otherwise, users outside of the course can still access child book pages of a private book parent.

Overrides CourseObjectNode::save

File

modules/course_book/course_book.classes.inc, line 142

Class

CourseObjectBook

Code

public function save() {

  // Take care of the parent book page.
  parent::save();
  if ($this
    ->hasNodePrivacySupport() && $this
    ->getOption('private') && module_exists('node_access_book')) {

    // Remove "view" permissions on all the child pages.
    $flat = array();
    $tree = menu_tree_all_data($this->node->book['menu_name']);
    _book_flatten_menu($tree, $flat);
    foreach ($flat as $item) {
      $nid = str_replace('node/', '', $item['link_path']);
      $node = node_load($nid);
      $settings = content_access_get_per_node_settings($node);
      $settings['view'] = array();
      content_access_save_per_node_settings($node, $settings);

      // Resave node to update access.
      node_access_acquire_grants($node);
    }
  }
}