diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php index 402776c..3db359b 100644 --- a/core/modules/book/src/BookManager.php +++ b/core/modules/book/src/BookManager.php @@ -278,7 +278,13 @@ public function updateOutline(NodeInterface $node) { // Prevent changes to the book outline if the node being saved is not the // default revision. - $updated = !$new && (($original = $this->loadBookLink($node->id(), FALSE)) && ($node->book['bid'] != $original['bid'] || $node->book['pid'] != $original['pid'])); + $updated = FALSE; + if (!$new) { + $original = $this->loadBookLink($node->id(), FALSE); + if ($node->book['bid'] != $original['bid'] || $node->book['pid'] != $original['pid'] || $node->book['weight'] != $original['weight']) { + $updated = TRUE; + } + } if (($new || $updated) && !$node->isDefaultRevision()) { return FALSE; } diff --git a/core/modules/book/tests/src/Functional/BookContentModerationTest.php b/core/modules/book/tests/src/Functional/BookContentModerationTest.php index 4411a87..c42feeb 100644 --- a/core/modules/book/tests/src/Functional/BookContentModerationTest.php +++ b/core/modules/book/tests/src/Functional/BookContentModerationTest.php @@ -78,6 +78,17 @@ public function testBookWithForwardRevisions() { $this->checkBookNode($book_1, [$book_1_nodes[0], $book_1_nodes[3], $book_1_nodes[4]], FALSE, FALSE, $book_1_nodes[0], []); $this->checkBookNode($book_1_nodes[0], [$book_1_nodes[1], $book_1_nodes[2]], $book_1, $book_1, $book_1_nodes[1], [$book_1]); + // Try to change the weight of Node 2. + $edit['book[weight]'] = 2; + $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save and Create New Draft')); + + $this->assertSession()->pageTextContains('You can only change the book outline for the published version of this content.'); + + // Check that the book outline did not change. + $this->book = $book_1; + $this->checkBookNode($book_1, [$book_1_nodes[0], $book_1_nodes[3], $book_1_nodes[4]], FALSE, FALSE, $book_1_nodes[0], []); + $this->checkBookNode($book_1_nodes[0], [$book_1_nodes[1], $book_1_nodes[2]], $book_1, $book_1, $book_1_nodes[1], [$book_1]); + // Save a new draft revision for the node without any changes and check that // the error message is not displayed. $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', [], t('Save and Create New Draft')); diff --git a/core/modules/book/tests/src/Kernel/BookForwardRevisionTest.php b/core/modules/book/tests/src/Kernel/BookForwardRevisionTest.php index 466f96c..df3e5bf 100644 --- a/core/modules/book/tests/src/Kernel/BookForwardRevisionTest.php +++ b/core/modules/book/tests/src/Kernel/BookForwardRevisionTest.php @@ -51,6 +51,10 @@ public function testBookWithForwardRevisions() { $book_1 = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]); $book_1->book['bid'] = 'new'; $book_1->save(); + $book_1_child = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]); + $book_1_child->book['bid'] = $book_1->id(); + $book_1_child->book['pid'] = $book_1->id(); + $book_1_child->save(); $book_2 = Node::create(['title' => $this->randomString(), 'type' => $content_type->id()]); $book_2->book['bid'] = 'new'; @@ -72,8 +76,25 @@ public function testBookWithForwardRevisions() { $child->setNewRevision(TRUE); $child->isDefaultRevision(FALSE); - $return = $book_manager->updateOutline($child); - $this->assertFalse($return, 'A forward revision can not change the book outline.'); + $this->assertFalse($book_manager->updateOutline($child), 'A forward revision can not change the book outline.'); + + // Check that the API doesn't allow us to change the book parent for + // forward revisions. + $child = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($child->id()); + $child->book['pid'] = $book_1_child->id(); + $child->setNewRevision(TRUE); + $child->isDefaultRevision(FALSE); + + $this->assertFalse($book_manager->updateOutline($child), 'A forward revision can not change the book outline.'); + + // Check that the API doesn't allow us to change the book weight for + // forward revisions. + $child = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($child->id()); + $child->book['weight'] = 2; + $child->setNewRevision(TRUE); + $child->isDefaultRevision(FALSE); + + $this->assertFalse($book_manager->updateOutline($child), 'A forward revision can not change the book outline.'); } }