diff --git a/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraintValidator.php b/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraintValidator.php index dbf2417..1b9f042 100644 --- a/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraintValidator.php +++ b/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraintValidator.php @@ -45,7 +45,14 @@ public static function create(ContainerInterface $container) { public function validate($entity, Constraint $constraint) { if (isset($entity) && !$entity->isNew() && !$entity->isDefaultRevision()) { /** @var \Drupal\Core\Entity\ContentEntityInterface $original */ - $original = $this->bookManager->loadBookLink($entity->id(), FALSE); + $original = $this->bookManager->loadBookLink($entity->id(), FALSE) ?: [ + 'bid' => 0, + 'weight' => 0, + ]; + if (empty($original['pid'])) { + $original['pid'] = -1; + } + if ($entity->book['bid'] != $original['bid']) { $this->context->buildViolation($constraint->message) ->atPath('book.bid') diff --git a/core/modules/book/tests/src/Functional/BookContentModerationTest.php b/core/modules/book/tests/src/Functional/BookContentModerationTest.php index c42feeb..a6101c4 100644 --- a/core/modules/book/tests/src/Functional/BookContentModerationTest.php +++ b/core/modules/book/tests/src/Functional/BookContentModerationTest.php @@ -56,6 +56,11 @@ 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]); + // Create a book draft with no changes, then publish it. + $this->drupalPostForm('node/' . $book_1->id() . '/edit', [], t('Save and Create New Draft')); + $this->assertSession()->pageTextNotContains('You can only change the book outline for the published version of this content.'); + $this->drupalPostForm('node/' . $book_1->id() . '/edit', [], t('Save and Publish')); + // Try to move Node 2 to a different parent. $edit['book[pid]'] = $book_1_nodes[3]->id(); $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save and Create New Draft'));