Issue #1933190 by larowlan: Fixed Fatal error when reordering book pages in book admin.
parent
a4a64ac0a7
commit
5a4ab9f033
|
@ -150,6 +150,8 @@ function book_admin_edit_submit($form, &$form_state) {
|
||||||
$order = array_flip(array_keys($form_state['input']['table']));
|
$order = array_flip(array_keys($form_state['input']['table']));
|
||||||
$form['table'] = array_merge($order, $form['table']);
|
$form['table'] = array_merge($order, $form['table']);
|
||||||
|
|
||||||
|
// Track updates.
|
||||||
|
$updated = FALSE;
|
||||||
foreach (element_children($form['table']) as $key) {
|
foreach (element_children($form['table']) as $key) {
|
||||||
if ($form['table'][$key]['#item']) {
|
if ($form['table'][$key]['#item']) {
|
||||||
$row = $form['table'][$key];
|
$row = $form['table'][$key];
|
||||||
|
@ -157,9 +159,11 @@ function book_admin_edit_submit($form, &$form_state) {
|
||||||
|
|
||||||
// Update menu item if moved.
|
// Update menu item if moved.
|
||||||
if ($row['plid']['#default_value'] != $values['plid'] || $row['weight']['#default_value'] != $values['weight']) {
|
if ($row['plid']['#default_value'] != $values['plid'] || $row['weight']['#default_value'] != $values['weight']) {
|
||||||
$row['#item']['plid'] = $values['plid'];
|
$menu_link = entity_load('menu_link', $values['mlid']);
|
||||||
$row['#item']['weight'] = $values['weight'];
|
$menu_link->weight = $values['weight'];
|
||||||
menu_link_save($row['#item']);
|
$menu_link->plid = $values['plid'];
|
||||||
|
$menu_link->save();
|
||||||
|
$updated = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the title if changed.
|
// 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())));
|
drupal_set_message(t('Updated book %title.', array('%title' => $form['#node']->label())));
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,5 +406,32 @@ class BookTest extends WebTestBase {
|
||||||
$this->assertTrue(book_type_is_allowed('bar'), 'Config book.settings:allowed_types contains the updated node type machine name "bar".');
|
$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".');
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue