summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-05-15 08:14:15 (GMT)
committerAlex Pott2018-05-15 08:14:15 (GMT)
commit1e7cb6ac40bcf28b17a9a20ca4861dba6cc3a39a (patch)
tree23ce3bdc5803eaf625fe5061d11a8f62b2f80873
parent00ed1ed469ac691651f6ae9ac603deb01ce8c4bb (diff)
Issue #2971779 by timmillwood, amateescu, alexpott, Sam152: Disallow moderation of internal entity types
-rw-r--r--core/modules/content_moderation/src/EntityTypeInfo.php2
-rw-r--r--core/modules/content_moderation/tests/src/Kernel/EntityTypeInfoTest.php30
2 files changed, 31 insertions, 1 deletions
diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php
index 80ce9d5..f54943d 100644
--- a/core/modules/content_moderation/src/EntityTypeInfo.php
+++ b/core/modules/content_moderation/src/EntityTypeInfo.php
@@ -130,7 +130,7 @@ class EntityTypeInfo implements ContainerInjectionInterface {
public function entityTypeAlter(array &$entity_types) {
foreach ($entity_types as $entity_type_id => $entity_type) {
// The ContentModerationState entity type should never be moderated.
- if ($entity_type->isRevisionable() && $entity_type_id != 'content_moderation_state') {
+ if ($entity_type->isRevisionable() && !$entity_type->isInternal()) {
$entity_types[$entity_type_id] = $this->addModerationToEntityType($entity_type);
}
}
diff --git a/core/modules/content_moderation/tests/src/Kernel/EntityTypeInfoTest.php b/core/modules/content_moderation/tests/src/Kernel/EntityTypeInfoTest.php
index a5791c8..09990fe 100644
--- a/core/modules/content_moderation/tests/src/Kernel/EntityTypeInfoTest.php
+++ b/core/modules/content_moderation/tests/src/Kernel/EntityTypeInfoTest.php
@@ -61,4 +61,34 @@ class EntityTypeInfoTest extends KernelTestBase {
$this->assertTrue($base_fields['moderation_state']->isTranslatable());
}
+ /**
+ * Test the correct entity types have moderation added.
+ *
+ * @covers ::entityTypeAlter
+ *
+ * @dataProvider providerTestEntityTypeAlter
+ */
+ public function testEntityTypeAlter($entity_type_id, $moderatable) {
+ $entity_types = $this->entityTypeManager->getDefinitions();
+ $this->assertSame($moderatable, $entity_types[$entity_type_id]->hasHandlerClass('moderation'));
+ }
+
+ /**
+ * Provides test data for testEntityTypeAlter().
+ *
+ * @return array
+ * An array of test cases, where each test case is an array with the
+ * following values:
+ * - An entity type ID.
+ * - Whether the entity type is moderatable or not.
+ */
+ public function providerTestEntityTypeAlter() {
+ $tests = [];
+ $tests['non_internal_non_revisionable'] = ['entity_test', FALSE];
+ $tests['non_internal_revisionable'] = ['entity_test_rev', TRUE];
+ $tests['internal_non_revisionable'] = ['entity_test_no_label', FALSE];
+ $tests['internal_revisionable'] = ['content_moderation_state', FALSE];
+ return $tests;
+ }
+
}