diff --git a/core/modules/book/lib/Drupal/book/BookManager.php b/core/modules/book/lib/Drupal/book/BookManager.php index 62feea9..bf978f4 100644 --- a/core/modules/book/lib/Drupal/book/BookManager.php +++ b/core/modules/book/lib/Drupal/book/BookManager.php @@ -299,7 +299,9 @@ public function updateOutline(NodeInterface $node) { if (empty($node->book['bid'])) { return FALSE; } - $new = empty($node->book['nid']); + // Ensure to create a new book if either the node itself is new, or the + // bid was selected the first time, so that the original_bid is still empty. + $new = empty($node->book['nid']) || empty($node->book['original_bid']); $node->book['nid'] = $node->id(); diff --git a/core/modules/book/lib/Drupal/book/Tests/BookTest.php b/core/modules/book/lib/Drupal/book/Tests/BookTest.php index 1d4ec43..a002f80 100644 --- a/core/modules/book/lib/Drupal/book/Tests/BookTest.php +++ b/core/modules/book/lib/Drupal/book/Tests/BookTest.php @@ -521,5 +521,24 @@ public function testBookOutline() { $this->drupalLogin($this->admin_user); $this->drupalGet('node/' . $book->id() . '/outline'); $this->assertRaw(t('Book outline')); + + // Create a new node and set the book after the node was created. + $node = $this->drupalCreateNode(array('type' => 'book')); + $edit = array(); + $edit['book[bid]'] = $node->id(); + $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); + $node = \Drupal::entityManager()->getStorageController('node')->load($node->id()); + + // Test the book array. + $this->assertEqual($node->book['nid'], $node->id()); + $this->assertEqual($node->book['bid'], $node->id()); + $this->assertEqual($node->book['depth'], 1); + $this->assertEqual($node->book['p1'], $node->id()); + $this->assertEqual($node->book['pid'], '0'); + + // Test the form itself. + $this->drupalGet('node/' . $node->id() . '/edit'); + $this->assertOptionSelected('edit-book-bid', $node->id()); } + }