When reordering book pages at admin/content/book/%node, you get the following fatal error:

 Fatal error: Call to a member function save() on a non-object in core/modules/menu_link/menu_link.module on line 120

It looks like a regression after the menu_link conversion. book_menu_subtree_data() returns an array of menu links, which book_admin_edit_submit() then calls a direct menu_link_save() on.

Tests are also needed, since testbot isn't catching this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

larowlan’s picture

Assigned: Unassigned » larowlan

Tackling this

larowlan’s picture

Assigned: larowlan » Unassigned
Status: Active » Needs review
Issue tags: -Needs tests
FileSize
2.99 KB
1.41 KB

Test only patch to demonstrate fail.
Test + fix.

duellj’s picture

Thanks for the quick patch larowlan! One thing that I noticed:

+++ b/core/modules/book/book.admin.inc
@@ -150,6 +150,8 @@ function book_admin_edit_submit($form, &$form_state) {
     if ($form['table'][$key]['#item']) {
       $row = $form['table'][$key];
@@ -159,7 +161,11 @@ function book_admin_edit_submit($form, &$form_state) {

@@ -159,7 +161,11 @@ function book_admin_edit_submit($form, &$form_state) {
       if ($row['plid']['#default_value'] != $values['plid'] || $row['weight']['#default_value'] != $values['weight']) {
         $row['#item']['plid'] = $values['plid'];
         $row['#item']['weight'] = $values['weight'];
-        menu_link_save($row['#item']);
+        $menu_link = entity_load('menu_link', $values['mlid']);
+        $menu_link->weight = $values['weight'];
+        $menu_link->plid = $values['plid'];
+        $menu_link->save();
+        $updated = TRUE;

Since #item is no longer used, should it be removed? At the very least, the assignments to $row['#item']['plid'] and $row['#item']['weight'] should be removed.

duellj’s picture

Also, the tests should probably be updated to include testing for changing book parents, not just weight.

larowlan’s picture

New patch adds test for altering parents and removes snippet indicated at #4.

larowlan’s picture

or rather the snippet at #3

Status: Needs review » Needs work

The last submitted patch, book-menu-order-1933190.5.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review

#5: book-menu-order-1933190.5.patch queued for re-testing.

andymartha’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
43.39 KB
44.99 KB

I can confirm that on a fresh installation of Drupal 8.x-dev on March 6th, 2013, the problems described in this description happened (see screenshot). After applying the patch book-menu-order-1933190.5.patch in #5 by larowlan, I was able to order the book pages at the described url by parents and weight with no errors. See screenshot.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Excellent! Bug fixes + tests is my favourite evening snack. :) Thanks a lot for the screenshots too, andymartha!

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.