diff --git a/includes/menu.inc b/includes/menu.inc index 2be0903..07a54e6 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -1485,13 +1485,17 @@ function menu_tree_collect_node_links(&$tree, &$node_links) { * menu_tree_collect_node_links(). */ function menu_tree_check_access(&$tree, $node_links = array()) { + global $menu_admin; + if ($node_links) { $nids = array_keys($node_links); $select = db_select('node', 'n'); $select->addField('n', 'nid'); - $select->condition('n.status', 1); + if (!$menu_admin) { + $select->condition('n.status', 1); + $select->addTag('node_access'); + } $select->condition('n.nid', $nids, 'IN'); - $select->addTag('node_access'); $nids = $select->execute()->fetchCol(); foreach ($nids as $nid) { foreach ($node_links[$nid] as $mlid => $link) { diff --git a/modules/book/book.admin.inc b/modules/book/book.admin.inc index cc3f08f..4ca2b95 100644 --- a/modules/book/book.admin.inc +++ b/modules/book/book.admin.inc @@ -161,12 +161,15 @@ function book_admin_edit_submit($form, &$form_state) { * @see book_admin_edit() */ function _book_admin_table($node, &$form) { + global $menu_admin; + $form['table'] = array( '#theme' => 'book_admin_table', '#tree' => TRUE, ); - + $menu_admin = TRUE; $tree = book_menu_subtree_data($node->book); + $menu_admin = FALSE; $tree = array_shift($tree); // Do not include the book item itself. if ($tree['below']) { $hash = drupal_hash_base64(serialize($tree['below'])); diff --git a/modules/book/book.module b/modules/book/book.module index 71b8994..44affb4 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -97,7 +97,7 @@ function book_node_view_link($node, $view_mode) { if (isset($node->book['depth'])) { if ($view_mode == 'full' && node_is_page($node)) { $child_type = variable_get('book_child_type', 'book'); - if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && $node->book['depth'] < MENU_MAX_DEPTH) { + if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->book['depth'] < MENU_MAX_DEPTH) { $links['book_add_child'] = array( 'title' => t('Add child page'), 'href' => 'node/add/' . str_replace('_', '-', $child_type), @@ -500,7 +500,7 @@ function _book_parent_select($book_link) { '#title' => t('Parent item'), '#default_value' => $book_link['plid'], '#description' => t('The parent page in the book. The maximum depth for a book and all child pages is !maxdepth. Some pages in the selected book may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)), - '#options' => book_toc($book_link['bid'], $book_link['parent_depth_limit'], array($book_link['mlid'])), + '#options' => book_toc($book_link['bid'], $book_link['parent_depth_limit'], array($book_link['mlid']), TRUE), '#attributes' => array('class' => array('book-title-select')), '#prefix' => '
', '#suffix' => '
', @@ -578,6 +578,12 @@ function _book_add_form_elements(&$form, &$form_state, $node) { $options = array(0 => '<' . t('none') . '>') + $options; } + // Prevent pages becoming disassociated when they belong to unpublished books. + if (!isset($options[$node->book['bid']])) { + $book = node_load($node->book['bid']); + $options[$node->book['bid']] = $book->title; + } + // Add a drop-down to select the destination book. $form['book']['bid'] = array( '#type' => 'select', @@ -1188,13 +1194,22 @@ function _book_toc_recurse($tree, $indent, &$toc, $exclude, $depth_limit) { * @param $exclude * Optional array of menu link ID values. Any link whose menu link ID is in * this array will be excluded (along with its children). + * @param $admin + * Set to true when retrieving admin access links and unpublished nodes will + * be included. * * @return * An array of (menu link ID, title) pairs for use as options for selecting a * book page. */ -function book_toc($bid, $depth_limit, $exclude = array()) { +function book_toc($bid, $depth_limit, $exclude = array(), $admin = FALSE) { + global $menu_admin; + if ($admin) { + $menu_admin = TRUE; + } $tree = menu_tree_all_data(book_menu_name($bid)); + $menu_admin = FALSE; + $toc = array(); _book_toc_recurse($tree, '', $toc, $exclude, $depth_limit);