Loading core/modules/content_moderation/src/ModerationInformation.php +1 −1 Changes for core/modules/content_moderation/src/ModerationInformation.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -157,7 +157,7 @@ public function hasPendingRevision(ContentEntityInterface $entity) { $latest_revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id(), $entity->language()->getId()); $default_revision_id = $entity->isDefaultRevision() && !$entity->isNewRevision() && ($revision_id = $entity->getRevisionId()) ? $revision_id : $this->getDefaultRevisionId($entity->getEntityTypeId(), $entity->id()); if ($latest_revision_id != $default_revision_id) { if ($latest_revision_id !== NULL && $latest_revision_id != $default_revision_id) { /** @var \Drupal\Core\Entity\ContentEntityInterface $latest_revision */ $latest_revision = $storage->loadRevision($latest_revision_id); $result = !$latest_revision->wasDefaultRevision(); Loading core/modules/content_moderation/tests/src/Kernel/ModerationInformationTest.php +32 −1 Changes for core/modules/content_moderation/tests/src/Kernel/ModerationInformationTest.php: 32 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -151,7 +151,38 @@ public function testIsDefaultRevisionPublishedMultilingual() { // language in a draft state and a non-default language in a published // state. The method returns TRUE if any of the languages for the default // revision are in a published state. $this->assertEquals(TRUE, $this->moderationInformation->isDefaultRevisionPublished($entity)); $this->assertTrue($this->moderationInformation->isDefaultRevisionPublished($entity)); } /** * @covers ::hasPendingRevision */ public function testHasPendingRevision() { $entity = EntityTestMulRevPub::create([ 'moderation_state' => 'published', ]); $entity->save(); // Add a translation as a new revision. $translated = $entity->addTranslation('de'); $translated->moderation_state = 'published'; $translated->setNewRevision(TRUE); // Test a scenario where the default revision exists with the default // language in a published state and a non-default language in an unsaved // state. $this->assertFalse($this->moderationInformation->hasPendingRevision($translated)); // Save the translation and assert there is no pending revision. $translated->save(); $this->assertFalse($this->moderationInformation->hasPendingRevision($translated)); // Create a new draft for the translation and assert there is a pending // revision. $translated->moderation_state = 'draft'; $translated->setNewRevision(TRUE); $translated->save(); $this->assertTrue($this->moderationInformation->hasPendingRevision($translated)); } } Loading
core/modules/content_moderation/src/ModerationInformation.php +1 −1 Changes for core/modules/content_moderation/src/ModerationInformation.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -157,7 +157,7 @@ public function hasPendingRevision(ContentEntityInterface $entity) { $latest_revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id(), $entity->language()->getId()); $default_revision_id = $entity->isDefaultRevision() && !$entity->isNewRevision() && ($revision_id = $entity->getRevisionId()) ? $revision_id : $this->getDefaultRevisionId($entity->getEntityTypeId(), $entity->id()); if ($latest_revision_id != $default_revision_id) { if ($latest_revision_id !== NULL && $latest_revision_id != $default_revision_id) { /** @var \Drupal\Core\Entity\ContentEntityInterface $latest_revision */ $latest_revision = $storage->loadRevision($latest_revision_id); $result = !$latest_revision->wasDefaultRevision(); Loading
core/modules/content_moderation/tests/src/Kernel/ModerationInformationTest.php +32 −1 Changes for core/modules/content_moderation/tests/src/Kernel/ModerationInformationTest.php: 32 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -151,7 +151,38 @@ public function testIsDefaultRevisionPublishedMultilingual() { // language in a draft state and a non-default language in a published // state. The method returns TRUE if any of the languages for the default // revision are in a published state. $this->assertEquals(TRUE, $this->moderationInformation->isDefaultRevisionPublished($entity)); $this->assertTrue($this->moderationInformation->isDefaultRevisionPublished($entity)); } /** * @covers ::hasPendingRevision */ public function testHasPendingRevision() { $entity = EntityTestMulRevPub::create([ 'moderation_state' => 'published', ]); $entity->save(); // Add a translation as a new revision. $translated = $entity->addTranslation('de'); $translated->moderation_state = 'published'; $translated->setNewRevision(TRUE); // Test a scenario where the default revision exists with the default // language in a published state and a non-default language in an unsaved // state. $this->assertFalse($this->moderationInformation->hasPendingRevision($translated)); // Save the translation and assert there is no pending revision. $translated->save(); $this->assertFalse($this->moderationInformation->hasPendingRevision($translated)); // Create a new draft for the translation and assert there is a pending // revision. $translated->moderation_state = 'draft'; $translated->setNewRevision(TRUE); $translated->save(); $this->assertTrue($this->moderationInformation->hasPendingRevision($translated)); } }