I need books that are restricted to a group. If I create content of type a only members of that group can see or edit it. But if book is involved members of other groups can now add content to books in a different group and they should not be able to see that content.

I looked at book access books made simple but neither provide the necessary tools.

Comments

nicxvan’s picture

I'm willing to do most of the legwork, but I would need some pointers. I think it may be best to have it as a helper module in og since book is core. I would like some similar function to the obsolete and unsupported og_book with some key changes. Allowing multiple books per group.

From looking at some code. I think the relevant bit in og_module that needs to be modified is here:

/**
 * Only show this group's book in the 'parent' dropdown list on the book form
 *
 * @param string $form_id
 * @param array $form
 */
function og_book_form_alter($form_id, &$form) {
  global $og_book_options;
  
  $group_node = og_get_group_context();
  if ($form_id == 'book_node_form' && $group_node) {
    og_book_get_options($group_node->nid);
    $form['parent'] = array(
      '#type' => 'select', 
      '#title' => t('Parent'), 
      '#default_value' => ($node->parent ? $node->parent : arg(4)), 
      '#options' => $og_book_options,
      '#weight' => -4,
      '#description' => t('The parent that this page belongs in.')
      );
  }
}

function og_book_get_options($gid) {
	$root_nid = og_book_get_root($gid);
  book_recurse($root_nid, 9, 'og_book_pre', 'og_book_post');
}

function og_book_get_root($gid) {
  $sql = "SELECT book_nid FROM {og_book} WHERE og_nid = %d";
  return db_result(db_query($sql, $gid));
}

The relevant hooks from book seem to be:
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/...
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/...
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/...

I don't know quite what to do with this so if someone can point me in the right direction I'll be happy to try to get this in place.