? book-589440-80.patch Index: book.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/book/book.admin.inc,v retrieving revision 1.8.2.3 diff -u -p -r1.8.2.3 book.admin.inc --- book.admin.inc 22 Oct 2008 19:26:01 -0000 1.8.2.3 +++ book.admin.inc 7 Feb 2011 22:20:13 -0000 @@ -170,6 +170,11 @@ function _book_admin_table($node, &$form * @see book_admin_edit() */ function _book_admin_table_tree($tree, &$form) { + // Adjust delta to be big enough to allow items to be moved from one chapter to another. + $tree_item = array_pop($tree); + $bid = $tree_item['link']['bid']; + $delta_estimate = _book_dynamic_delta($bid); + foreach ($tree as $data) { $form['book-admin-'. $data['link']['nid']] = array( '#item' => $data['link'], Index: book.module =================================================================== RCS file: /cvs/drupal/drupal/modules/book/book.module,v retrieving revision 1.454.2.6 diff -u -p -r1.454.2.6 book.module --- book.module 25 Feb 2009 11:47:37 -0000 1.454.2.6 +++ book.module 7 Feb 2011 22:20:14 -0000 @@ -386,7 +386,7 @@ function _book_add_form_elements(&$form, '#type' => 'weight', '#title' => t('Weight'), '#default_value' => $node->book['weight'], - '#delta' => 15, + '#delta' => _book_dynamic_delta($node->book['bid']), '#weight' => 5, '#description' => t('Pages at a given level are ordered first by weight and then by title.'), ); @@ -1094,3 +1094,25 @@ function book_menu_subtree_data($item) { return $tree[$cid]; } +/** + * Calculate a reasonable value for delta to be used in book management page or book edit form. + * + * @param $bid + * Book id. + * @return + * Delta value as an integer. + */ +function _book_dynamic_delta($bid) { + //Count all items in the book. + $toc_count_all = count(book_toc($bid, array(), 8)); + //Count all first level items. + $toc_count_first_child_level = count(book_toc($bid, array(), 2)) - 1; //Exclude the book itself + + //Calculate an estimate + $delta_estimate = ceil($toc_count_all / $toc_count_first_child_level); // Estimated delta value to be big enough + if ($delta_estimate < 15) { + $delta_estimate = 15; + } + + return $delta_estimate; +}