Commit 5a4ab9f0 authored by webchick's avatar webchick

Issue #1933190 by larowlan: Fixed Fatal error when reordering book pages in book admin.

parent a4a64ac0
......@@ -150,6 +150,8 @@ function book_admin_edit_submit($form, &$form_state) {
$order = array_flip(array_keys($form_state['input']['table']));
$form['table'] = array_merge($order, $form['table']);
// Track updates.
$updated = FALSE;
foreach (element_children($form['table']) as $key) {
if ($form['table'][$key]['#item']) {
$row = $form['table'][$key];
......@@ -157,9 +159,11 @@ function book_admin_edit_submit($form, &$form_state) {
// Update menu item if moved.
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;
}
// Update the title if changed.
......@@ -176,6 +180,12 @@ function book_admin_edit_submit($form, &$form_state) {
}
}
}
if ($updated) {
// Flush static and cache.
drupal_static_reset('book_menu_subtree_data');
$cid = 'links:' . $form['#node']->book['menu_name'] . ':subtree-cid:' . $form['#node']->book['mlid'];
cache('menu')->delete($cid);
}
drupal_set_message(t('Updated book %title.', array('%title' => $form['#node']->label())));
}
......
......@@ -406,5 +406,32 @@ function testBookNodeTypeChange() {
$this->assertTrue(book_type_is_allowed('bar'), 'Config book.settings:allowed_types contains the updated node type machine name "bar".');
$this->assertFalse(book_type_is_allowed('book'), 'Config book.settings:allowed_types does not contain the old node type machine name "book".');
}
}
/**
* Tests re-ordering of books.
*/
public function testBookOrdering() {
// Create new book.
$nodes = $this->createBook();
$book = $this->book;
$this->drupalLogin($this->admin_user);
$node1 = $this->createBookNode($book->nid);
$node2 = $this->createBookNode($book->nid);
$plid = $node1->book['mlid'];
// Head to admin screen and attempt to re-order.
$this->drupalGet('admin/content/book/' . $book->nid);
$edit = array(
"table[book-admin-{$node1->nid}][weight]" => 1,
"table[book-admin-{$node2->nid}][weight]" => 2,
// Put node 2 under node 1.
"table[book-admin-{$node2->nid}][plid]" => $plid,
);
$this->drupalPost(NULL, $edit, t('Save book pages'));
// Verify weight was updated.
$this->assertFieldByName("table[book-admin-{$node1->nid}][weight]", 1);
$this->assertFieldByName("table[book-admin-{$node2->nid}][weight]", 2);
$this->assertFieldByName("table[book-admin-{$node2->nid}][plid]", $plid);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment