diff --git a/core/modules/content_moderation/src/ModerationInformation.php b/core/modules/content_moderation/src/ModerationInformation.php index abc93f403f0..7aad535685f 100644 --- a/core/modules/content_moderation/src/ModerationInformation.php +++ b/core/modules/content_moderation/src/ModerationInformation.php @@ -157,7 +157,7 @@ class ModerationInformation implements ModerationInformationInterface { $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(); diff --git a/core/modules/content_moderation/tests/src/Kernel/ModerationInformationTest.php b/core/modules/content_moderation/tests/src/Kernel/ModerationInformationTest.php index bff2a972a51..25703093ab0 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ModerationInformationTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ModerationInformationTest.php @@ -151,7 +151,38 @@ class ModerationInformationTest extends KernelTestBase { // 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)); } }