summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-10-03 09:51:47 (GMT)
committerAlex Pott2014-10-03 09:51:47 (GMT)
commit2e60dbb0cd10596ddf92455afbf62126ee2e040f (patch)
treee0adf6828ba519eaed297258c1fcb440242a4235
parent8d97ffff06e643d0508be610284bed57bdbf53df (diff)
Issue #2346313 by Cottser, andrei.dincu | joelpittet: Fixed Fatal error when submitting the book admin form with an empty book.
-rw-r--r--core/modules/book/src/Form/BookAdminEditForm.php52
-rw-r--r--core/modules/book/src/Tests/BookTest.php15
2 files changed, 42 insertions, 25 deletions
diff --git a/core/modules/book/src/Form/BookAdminEditForm.php b/core/modules/book/src/Form/BookAdminEditForm.php
index fb1e3e8..2cf7a18 100644
--- a/core/modules/book/src/Form/BookAdminEditForm.php
+++ b/core/modules/book/src/Form/BookAdminEditForm.php
@@ -97,31 +97,33 @@ class BookAdminEditForm extends FormBase {
// Save elements in the same order as defined in post rather than the form.
// This ensures parents are updated before their children, preventing orphans.
$user_input = $form_state->getUserInput();
- $order = array_flip(array_keys($user_input['table']));
- $form['table'] = array_merge($order, $form['table']);
-
- foreach (Element::children($form['table']) as $key) {
- if ($form['table'][$key]['#item']) {
- $row = $form['table'][$key];
- $values = $form_state->getValue(array('table', $key));
-
- // Update menu item if moved.
- if ($row['pid']['#default_value'] != $values['pid'] || $row['weight']['#default_value'] != $values['weight']) {
- $link = $this->bookManager->loadBookLink($values['nid'], FALSE);
- $link['weight'] = $values['weight'];
- $link['pid'] = $values['pid'];
- $this->bookManager->saveBookLink($link, FALSE);
- }
-
- // Update the title if changed.
- if ($row['title']['#default_value'] != $values['title']) {
- $node = $this->nodeStorage->load($values['nid']);
- $node->revision_log = $this->t('Title changed from %original to %current.', array('%original' => $node->label(), '%current' => $values['title']));
- $node->title = $values['title'];
- $node->book['link_title'] = $values['title'];
- $node->setNewRevision();
- $node->save();
- $this->logger('content')->notice('book: updated %title.', array('%title' => $node->label(), 'link' => $node->link($this->t('View'))));
+ if (isset($user_input['table'])) {
+ $order = array_flip(array_keys($user_input['table']));
+ $form['table'] = array_merge($order, $form['table']);
+
+ foreach (Element::children($form['table']) as $key) {
+ if ($form['table'][$key]['#item']) {
+ $row = $form['table'][$key];
+ $values = $form_state->getValue(array('table', $key));
+
+ // Update menu item if moved.
+ if ($row['pid']['#default_value'] != $values['pid'] || $row['weight']['#default_value'] != $values['weight']) {
+ $link = $this->bookManager->loadBookLink($values['nid'], FALSE);
+ $link['weight'] = $values['weight'];
+ $link['pid'] = $values['pid'];
+ $this->bookManager->saveBookLink($link, FALSE);
+ }
+
+ // Update the title if changed.
+ if ($row['title']['#default_value'] != $values['title']) {
+ $node = $this->nodeStorage->load($values['nid']);
+ $node->revision_log = $this->t('Title changed from %original to %current.', array('%original' => $node->label(), '%current' => $values['title']));
+ $node->title = $values['title'];
+ $node->book['link_title'] = $values['title'];
+ $node->setNewRevision();
+ $node->save();
+ $this->logger('content')->notice('book: updated %title.', array('%title' => $node->label(), 'link' => $node->link($this->t('View'))));
+ }
}
}
}
diff --git a/core/modules/book/src/Tests/BookTest.php b/core/modules/book/src/Tests/BookTest.php
index 591ac38..b229104 100644
--- a/core/modules/book/src/Tests/BookTest.php
+++ b/core/modules/book/src/Tests/BookTest.php
@@ -96,6 +96,21 @@ class BookTest extends WebTestBase {
}
/**
+ * Tests saving the book outline on an empty book.
+ */
+ function testEmptyBook() {
+ // Create a new empty book.
+ $this->drupalLogin($this->book_author);
+ $book = $this->createBookNode('new');
+ $this->drupalLogout();
+
+ // Log in as a user with access to the book outline and save the form.
+ $this->drupalLogin($this->admin_user);
+ $this->drupalPostForm('admin/structure/book/' . $book->id(), array(), t('Save book pages'));
+ $this->assertText(t('Updated book @book.', array('@book' => $book->label())));
+ }
+
+ /**
* Tests book functionality through node interfaces.
*/
function testBook() {