? modules/node/node.content_forms.inc
? modules/system/Untitled-1
Index: modules/book/book.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/book/book.module,v
retrieving revision 1.433
diff -u -p -r1.433 book.module
--- modules/book/book.module	11 Aug 2007 14:06:15 -0000	1.433
+++ modules/book/book.module	13 Aug 2007 00:16:44 -0000
@@ -384,12 +384,15 @@ function _book_parent_select($book_link)
     $form['#prefix'] .= '<em>'. t('No book selected.') .'</em>';
   }
   else {
+    // If the item has children, there is an added limit to the depth of valid parents.
+    $limit = MENU_MAX_DEPTH - 1 - ($book_link['has_children'] ? menu_link_children_relative_depth($book_link) : 0);
+
     $form = array(
       '#type' => 'select',
       '#title' => t('Parent item'),
       '#default_value' => $book_link['plid'],
-      '#description' => t('The parent page in the book.'),
-      '#options' => book_toc($book_link['bid'], array($book_link['mlid'])),
+      '#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'], array($book_link['mlid']), $limit),
     );
   }
   return $form;
@@ -434,11 +437,18 @@ function _book_add_form_elements(&$form,
     '#description' => t('Pages at a given level are ordered first by weight and then by title.'),
   );
   $options = array();
-
-  foreach (book_get_books() as $book) {
-    $options[$book['nid']] = $book['title'];
-  }
   $nid = isset($node->nid) ? $node->nid : 'new';
+    
+  if (isset($node->nid) && ($nid == $node->book['original_bid']) && $node->book['has_children'] && (MENU_MAX_DEPTH - 1 - menu_link_children_relative_depth($node->book) == 0)) {
+    // This is the top level node in a maximum depth book. The page cannot be moved.
+    $options[$node->nid] = $node->title;
+  }
+  else {
+    foreach (book_get_books() as $book) {
+      $options[$book['nid']] = $book['title'];
+    }
+  }
+
   if (user_access('create new books') && ($nid == 'new' || ($nid != $node->book['original_bid']))) {
     // The node can become a new book, if it is not one already.
     $options = array($nid => '<'. t('create a new book') .'>') + $options;
@@ -951,12 +961,16 @@ function theme_book_navigation($book_lin
 /**
  * A recursive helper function for book_toc().
  */
-function _book_toc_recurse($tree, $indent, &$toc, $exclude) {
+function _book_toc_recurse($tree, $indent, &$toc, $exclude, $depth_limit) {
   foreach ($tree as $data) {
+    if ($data['link']['depth'] > $depth_limit) {
+      // Don't iterate through any links on this level..
+      break;
+    }
     if (!in_array($data['link']['mlid'], $exclude)) {
       $toc[$data['link']['mlid']] = $indent .' '. truncate_utf8($data['link']['title'], 30, TRUE, TRUE);
-      if ($data['below'] && $data['link']['depth'] < MENU_MAX_DEPTH - 1) {
-        _book_toc_recurse($data['below'], $indent .'--', $toc, $exclude);
+      if ($data['below']) {
+        _book_toc_recurse($data['below'], $indent .'--', $toc, $exclude, $depth_limit);
       }
     }
   }
@@ -970,14 +984,16 @@ function _book_toc_recurse($tree, $inden
  * @param $exclude
  *   Optional array of mlid values.  Any link whose mlid is in this array
  *   will be excluded (along with its children).
+ * @param $depth_limit
+ *   Any link deeper than this value will be excluded (along with its children).
  * @return
  *   An array of mlid, title pairs for use as options for selecting a book page.
  */
-function book_toc($bid, $exclude = array()) {
+function book_toc($bid, $exclude = array(), $depth_limit) {
 
   $tree = menu_tree_all_data(book_menu_name($bid));
   $toc = array();
-  _book_toc_recurse($tree, '', $toc, $exclude);
+  _book_toc_recurse($tree, '', $toc, $exclude, $depth_limit);
 
   return $toc;
 }
Index: modules/menu/menu.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/menu/menu.module,v
retrieving revision 1.133
diff -u -p -r1.133 menu.module
--- modules/menu/menu.module	11 Aug 2007 14:06:15 -0000	1.133
+++ modules/menu/menu.module	13 Aug 2007 00:16:45 -0000
@@ -335,6 +335,7 @@ function menu_edit_item(&$form_state, $t
     '#title' => t('Parent item'),
     '#default_value' => $default,
     '#options' => $options,
+    '#description' => t('The maximum depth for an item and all its children is fixed at !maxdepth.  Some menu items may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)),
   );
   $form['weight'] = array(
     '#type' => 'weight',
@@ -391,10 +392,13 @@ function menu_edit_item_submit($form, &$
  */
 function menu_parent_options($menus, $item) {
 
+  // If the item has children, there is an added limit to the depth of valid parents.
+  $limit = MENU_MAX_DEPTH - 1 - (($item['mlid'] && $item['has_children']) ? menu_link_children_relative_depth($item) : 0);
+  
   foreach ($menus as $menu_name => $title) {
     $tree = menu_tree_all_data($menu_name, NULL);
     $options[$menu_name .':0'] = '<'. $title .'>';
-    _menu_parents_recurse($tree, $menu_name, '--', $options, $item['mlid']);
+    _menu_parents_recurse($tree, $menu_name, '--', $options, $item['mlid'], $limit);
   }
   return $options;
 }
@@ -402,16 +406,20 @@ function menu_parent_options($menus, $it
 /**
  * Recursive helper function for menu_parent_options().
  */
-function _menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude) {
+function _menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, $depth_limit) {
   foreach ($tree as $data) {
-    if ($data['link']['mlid'] != $exclude && $data['link']['hidden'] >= 0) {
+    if ($data['link']['depth'] > $depth_limit) {
+      // Don't iterate through any links on this level..
+      break;
+    }
+    if ($data['link']['mlid'] != $exclude) {
       $title = $indent .' '. truncate_utf8($data['link']['title'], 30, TRUE, FALSE);
       if ($data['link']['hidden']) {
         $title .= ' ('. t('disabled') .')';
       }
       $options[$menu_name .':'. $data['link']['mlid']] = $title;
-      if ($data['below'] && $data['link']['depth'] < MENU_MAX_DEPTH - 1) {
-        _menu_parents_recurse($data['below'], $menu_name, $indent .'--', $options, $exclude);
+      if ($data['below']) {
+        _menu_parents_recurse($data['below'], $menu_name, $indent .'--', $options, $exclude, $depth_limit);
       }
     }
   }
@@ -763,6 +771,7 @@ function menu_form_alter(&$form, $form_s
       '#title' => t('Parent item'),
       '#default_value' => $default,
       '#options' => $options,
+      '#description' => t('The maximum depth for an item and all its children is fixed at !maxdepth.  Some menu items may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)),
     );
     $form['#submit'][] = 'menu_node_form_submit';
 
