diff --git a/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraint.php b/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraint.php index 677d36c..4017bc0 100644 --- a/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraint.php +++ b/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraint.php @@ -14,6 +14,6 @@ */ class BookOutlineConstraint extends Constraint { - public $message = 'This is not the default revision. You can only change the book outline for the published version of this content.'; + public $message = 'You can only change the book outline for the published version of this content.'; } diff --git a/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraintValidator.php b/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraintValidator.php index 66ff644..7adb0a7 100644 --- a/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraintValidator.php +++ b/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraintValidator.php @@ -46,8 +46,15 @@ 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); - if ($entity->book['bid'] != $original['bid'] || $entity->book['pid'] != $original['pid']) { + if ($entity->book['bid'] != $original['bid']) { $this->context->buildViolation($constraint->message) + ->atPath('book.bid') + ->setInvalidValue($entity) + ->addViolation(); + } + elseif ($entity->book['pid'] != $original['pid']) { + $this->context->buildViolation($constraint->message) + ->atPath('book.pid') ->setInvalidValue($entity) ->addViolation(); } diff --git a/core/modules/book/tests/src/Functional/BookContentModerationTest.php b/core/modules/book/tests/src/Functional/BookContentModerationTest.php index 24e3d15..4411a87 100644 --- a/core/modules/book/tests/src/Functional/BookContentModerationTest.php +++ b/core/modules/book/tests/src/Functional/BookContentModerationTest.php @@ -60,7 +60,7 @@ public function testBookWithForwardRevisions() { $edit['book[pid]'] = $book_1_nodes[3]->id(); $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save and Create New Draft')); - $this->assertSession()->pageTextContains('This is not the default revision. You can only change the book outline for the published version of this content.'); + $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; @@ -71,7 +71,7 @@ public function testBookWithForwardRevisions() { $edit['book[bid]'] = $book_2->id(); $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', $edit, t('Save and Create New Draft')); - $this->assertSession()->pageTextContains('This is not the default revision. You can only change the book outline for the published version of this content.'); + $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; @@ -82,7 +82,7 @@ public function testBookWithForwardRevisions() { // the error message is not displayed. $this->drupalPostForm('node/' . $book_1_nodes[1]->id() . '/edit', [], t('Save and Create New Draft')); - $this->assertSession()->pageTextNotContains('This is not the default revision. You can only change the book outline for the published version of this content.'); + $this->assertSession()->pageTextNotContains('You can only change the book outline for the published version of this content.'); } }