diff --git a/core/modules/content_moderation/src/EntityOperations.php b/core/modules/content_moderation/src/EntityOperations.php index 4cfe798..d76a35b 100644 --- a/core/modules/content_moderation/src/EntityOperations.php +++ b/core/modules/content_moderation/src/EntityOperations.php @@ -173,7 +173,7 @@ protected function updateOrCreateFromEntity(EntityInterface $entity) { } // Sync translations. - if ($entity->getEntityType()->isTranslatable()) { + if ($entity->getEntityType()->hasKey('langcode')) { $entity_langcode = $entity->language()->getId(); if (!$content_moderation_state->hasTranslation($entity_langcode)) { $content_moderation_state->addTranslation($entity_langcode); diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php index 566b3c0..2765f29 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php @@ -221,6 +221,47 @@ public function testMultilingualModeration() { * Tests that non-translatable entity types can be moderated. */ public function testNonTranslatableEntityTypeModeration() { + // Make the 'entity_test_with_bundle' entity type revisionable. + $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_with_bundle'); + $keys = $entity_type->getKeys(); + $keys['revision'] = 'revision_id'; + $entity_type->set('entity_keys', $keys); + \Drupal::state()->set('entity_test_with_bundle.entity_type', $entity_type); + \Drupal::entityDefinitionUpdateManager()->applyUpdates(); + + // Create a test bundle. + $entity_test_bundle = EntityTestBundle::create([ + 'id' => 'example', + ]); + $entity_test_bundle->setThirdPartySetting('content_moderation', 'enabled', TRUE); + $entity_test_bundle->setThirdPartySetting('content_moderation', 'allowed_moderation_states', [ + 'draft', + 'published' + ]); + $entity_test_bundle->setThirdPartySetting('content_moderation', 'default_moderation_state', 'draft'); + $entity_test_bundle->save(); + + // Check that the tested entity type is not translatable. + $entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_with_bundle'); + $this->assertFalse($entity_type->isTranslatable(), 'The test entity type is not translatable.'); + + // Create a test entity. + $entity_test_with_bundle = EntityTestWithBundle::create([ + 'type' => 'example' + ]); + $entity_test_with_bundle->save(); + $this->assertEquals('draft', $entity_test_with_bundle->moderation_state->entity->id()); + + $entity_test_with_bundle->moderation_state->target_id = 'published'; + $entity_test_with_bundle->save(); + + $this->assertEquals('published', EntityTestWithBundle::load($entity_test_with_bundle->id())->moderation_state->entity->id()); + } + + /** + * Tests that non-langcode entity types can be moderated. + */ + public function testNonLangcodeEntityTypeModeration() { // Make the 'entity_test_with_bundle' entity type revisionable and unset // the langcode entity key. $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_with_bundle');