diff --git a/core/modules/content_moderation/config/schema/content_moderation.schema.yml b/core/modules/content_moderation/config/schema/content_moderation.schema.yml index 7f9e8fd..1b490bb 100644 --- a/core/modules/content_moderation/config/schema/content_moderation.schema.yml +++ b/core/modules/content_moderation/config/schema/content_moderation.schema.yml @@ -70,6 +70,22 @@ block_content.type.*.third_party.content_moderation: type: string label: 'Moderation state for new block content' +entity_test.type.*.third_party.content_moderation: + type: mapping + label: 'Enable moderation states for this Entity Test type' + mapping: + enabled: + type: boolean + label: 'Moderation states enabled' + allowed_moderation_states: + type: sequence + sequence: + type: string + label: 'Moderation state' + default_moderation_state: + type: string + label: 'Moderation state for new Entity Test' + views.filter.latest_revision: type: views_filter label: 'Latest revision' diff --git a/core/modules/content_moderation/src/EntityOperations.php b/core/modules/content_moderation/src/EntityOperations.php index 4e06d73..60224b4 100644 --- a/core/modules/content_moderation/src/EntityOperations.php +++ b/core/modules/content_moderation/src/EntityOperations.php @@ -200,7 +200,7 @@ protected function updateOrCreateFromEntity(EntityInterface $entity) { } // Sync translations. - if ($entity->isTranslatable()) { + if ($entity->getEntityType()->isTranslatable()) { $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/src/Plugin/Field/ModerationStateFieldItemList.php b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php index 7e53448..1080d9f 100644 --- a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php +++ b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php @@ -39,7 +39,7 @@ protected function getModerationState() { ->loadRevision($revision_to_load); // Return the correct translation. - if ($entity->isTranslatable()) { + if ($entity->getEntityType()->isTranslatable()) { $langcode = $entity->language()->getId(); if (!$content_moderation_state->hasTranslation($langcode)) { $content_moderation_state->addTranslation($langcode); diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php index 3ba37a2..72591e1 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php @@ -4,6 +4,9 @@ use Drupal\content_moderation\Entity\ContentModerationState; use Drupal\content_moderation\Entity\ModerationState; +use Drupal\Core\Config\Entity\ThirdPartySettingsInterface; +use Drupal\entity_test\Entity\EntityTestRev; +use Drupal\entity_test\Entity\EntityTestRevType; use Drupal\KernelTests\KernelTestBase; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\node\Entity\Node; @@ -27,6 +30,7 @@ class ContentModerationStateTest extends KernelTestBase { 'system', 'language', 'content_translation', + 'entity_test', ]; /** @@ -38,6 +42,7 @@ protected function setUp() { $this->installSchema('node', 'node_access'); $this->installEntitySchema('node'); $this->installEntitySchema('user'); + $this->installEntitySchema('entity_test_rev'); $this->installEntitySchema('content_moderation_state'); $this->installConfig('content_moderation'); } @@ -210,6 +215,32 @@ public function testMultilingualModeration() { $this->assertEquals(6, $english_node->getRevisionId()); } + public function testEntityTestModeration() { + $entity_test_rev_type = EntityTestRevType::create([ + 'id' => 'example', + ]); + if ($entity_test_rev_type instanceof ThirdPartySettingsInterface) { + $entity_test_rev_type->setThirdPartySetting('content_moderation', 'enabled', TRUE); + $entity_test_rev_type->setThirdPartySetting('content_moderation', 'allowed_moderation_states', [ + 'draft', + 'published' + ]); + $entity_test_rev_type->setThirdPartySetting('content_moderation', 'default_moderation_state', 'draft'); + } + $entity_test_rev_type->save(); + $entity_test_rev = EntityTestRev::create([ + 'type' => 'example' + ]); + $entity_test_rev->save(); + $this->assertEquals('draft', $entity_test_rev->moderation_state->entity->id()); + + $published = ModerationState::load('published'); + $entity_test_rev->moderation_state->entity = $published; + $entity_test_rev->save(); + + $this->assertEquals('published', $entity_test_rev->moderation_state->entity->id()); + } + /** * Reloads the node after clearing the static cache. * diff --git a/core/modules/system/tests/modules/entity_test/config/schema/entity_test_rev_type.schema.yml b/core/modules/system/tests/modules/entity_test/config/schema/entity_test_rev_type.schema.yml index e69de29..8aae9c1 100644 --- a/core/modules/system/tests/modules/entity_test/config/schema/entity_test_rev_type.schema.yml +++ b/core/modules/system/tests/modules/entity_test/config/schema/entity_test_rev_type.schema.yml @@ -0,0 +1,12 @@ +entity_test.type.*: + type: config_entity + label: 'EntityTestRev type config' + mapping: + id: + type: string + label: 'ID' + label: + type: label + label: 'Label' + uuid: + type: string diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php index 47035ea..97e8ecd 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php @@ -11,6 +11,7 @@ * @ContentEntityType( * id = "entity_test_rev", * label = @Translation("Test entity - revisions"), + * bundle_label = @Translation("EntityTestRev type"), * handlers = { * "access" = "Drupal\entity_test\EntityTestAccessControlHandler", * "view_builder" = "Drupal\entity_test\EntityTestViewBuilder", @@ -28,6 +29,7 @@ * base_table = "entity_test_rev", * revision_table = "entity_test_rev_revision", * admin_permission = "administer entity_test content", + * bundle_entity_type = "entity_test_rev_type", * entity_keys = { * "id" = "id", * "uuid" = "uuid", diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRevType.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRevType.php index e69de29..9bc719a 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRevType.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRevType.php @@ -0,0 +1,42 @@ +