Enable an optional restriction for books selection by content type

This commit is contained in:
Manuel Cillero 2017-07-26 09:01:45 +02:00
parent e76acf63f2
commit b98028868f

View file

@ -78,7 +78,7 @@ function book_menu() {
'title' => 'Books', 'title' => 'Books',
'description' => "Manage your site's book outlines.", 'description' => "Manage your site's book outlines.",
'page callback' => 'book_admin_overview', 'page callback' => 'book_admin_overview',
'access arguments' => array('administer book outlines'), 'access arguments' => array('administer site configuration'),
'file' => 'book.admin.inc', 'file' => 'book.admin.inc',
); );
$items['admin/content/book/list'] = array( $items['admin/content/book/list'] = array(
@ -191,7 +191,7 @@ function book_block($op = 'list', $delta = 0, $edit = array()) {
$block['subject'] = t('Book navigation'); $block['subject'] = t('Book navigation');
$book_menus = array(); $book_menus = array();
$pseudo_tree = array(0 => array('below' => FALSE)); $pseudo_tree = array(0 => array('below' => FALSE));
foreach (book_get_books() as $book_id => $book) { foreach (book_get_books($node->type) as $book_id => $book) {
if ($book['bid'] == $current_bid) { if ($book['bid'] == $current_bid) {
// If the current page is a node associated with a book, the menu // If the current page is a node associated with a book, the menu
// needs to be retrieved. // needs to be retrieved.
@ -255,7 +255,7 @@ function theme_book_title_link($link) {
* This list may be used for generating a list of all the books, or for building * This list may be used for generating a list of all the books, or for building
* the options for a form select. * the options for a form select.
*/ */
function book_get_books() { function book_get_books($type = null) {
static $all_books; static $all_books;
if (!isset($all_books)) { if (!isset($all_books)) {
@ -268,9 +268,11 @@ function book_get_books() {
if ($nids) { if ($nids) {
$result2 = db_query(db_rewrite_sql("SELECT n.type, n.title, b.*, ml.* FROM {book} b INNER JOIN {node} n on b.nid = n.nid INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE n.nid IN (". implode(',', $nids) .") AND n.status = 1 ORDER BY ml.weight, ml.link_title")); $result2 = db_query(db_rewrite_sql("SELECT n.type, n.title, b.*, ml.* FROM {book} b INNER JOIN {node} n on b.nid = n.nid INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE n.nid IN (". implode(',', $nids) .") AND n.status = 1 ORDER BY ml.weight, ml.link_title"));
while ($link = db_fetch_array($result2)) { while ($link = db_fetch_array($result2)) {
$link['href'] = $link['link_path']; if (!isset($type) || !variable_get('book_restrict_to_types', false) || $link['type'] == $type) {
$link['options'] = unserialize($link['options']); $link['href'] = $link['link_path'];
$all_books[$link['bid']] = $link; $link['options'] = unserialize($link['options']);
$all_books[$link['bid']] = $link;
}
} }
} }
} }
@ -401,7 +403,7 @@ function _book_add_form_elements(&$form, $node) {
$options[$node->nid] = $node->title; $options[$node->nid] = $node->title;
} }
else { else {
foreach (book_get_books() as $book) { foreach (book_get_books($node->type) as $book) {
$options[$book['nid']] = $book['title']; $options[$book['nid']] = $book['title'];
} }
} }
@ -560,7 +562,8 @@ function book_prev($book_link) {
// The previous page in the book may be a child of the previous visible link. // The previous page in the book may be a child of the previous visible link.
if ($prev['depth'] == $book_link['depth'] && $prev['has_children']) { if ($prev['depth'] == $book_link['depth'] && $prev['has_children']) {
// The subtree will have only one link at the top level - get its data. // The subtree will have only one link at the top level - get its data.
$data = array_shift(book_menu_subtree_data($prev)); $subtree_data = book_menu_subtree_data($prev);
$data = array_shift($subtree_data);
// The link of interest is the last child - iterate to find the deepest one. // The link of interest is the last child - iterate to find the deepest one.
while ($data['below']) { while ($data['below']) {
$data = end($data['below']); $data = end($data['below']);