summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Rowlands2017-07-20 03:15:46 (GMT)
committerLee Rowlands2017-07-20 03:15:46 (GMT)
commit930a35b962c898f42c2808a2a28f610830bf6d85 (patch)
treed6d45f810d73cd190cf9d4a51097c32c7b6d32e8
parentba0ac0fde374c2b1a1922440257015967f898b82 (diff)
Issue #2843753 by Wim Leers, amateescu: Prevent ContentModerationState from being exposed by REST's EntityResource
-rw-r--r--core/modules/content_moderation/content_moderation.module10
-rw-r--r--core/modules/content_moderation/tests/src/Kernel/ContentModerationStateResourceTest.php38
2 files changed, 48 insertions, 0 deletions
diff --git a/core/modules/content_moderation/content_moderation.module b/core/modules/content_moderation/content_moderation.module
index b67fbd3..0dc03bf 100644
--- a/core/modules/content_moderation/content_moderation.module
+++ b/core/modules/content_moderation/content_moderation.module
@@ -262,3 +262,13 @@ function content_moderation_workflow_insert(WorkflowInterface $entity) {
function content_moderation_workflow_update(WorkflowInterface $entity) {
content_moderation_workflow_insert($entity);
}
+
+/**
+ * Implements hook_rest_resource_alter().
+ */
+function content_moderation_rest_resource_alter(&$definitions) {
+ // ContentModerationState is an internal entity type. Therefore it should not
+ // be exposed via REST.
+ // @see \Drupal\content_moderation\ContentModerationStateAccessControlHandler
+ unset($definitions['entity:content_moderation_state']);
+}
diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateResourceTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateResourceTest.php
new file mode 100644
index 0000000..cc09e59
--- /dev/null
+++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateResourceTest.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Drupal\Tests\content_moderation\Kernel;
+
+use Drupal\Component\Plugin\Exception\PluginNotFoundException;
+use Drupal\KernelTests\KernelTestBase;
+use Drupal\rest\Entity\RestResourceConfig;
+use Drupal\rest\RestResourceConfigInterface;
+
+/**
+ * @group content_moderation
+ */
+class ContentModerationStateResourceTest extends KernelTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['serialization', 'rest', 'content_moderation'];
+
+ /**
+ * @see content_moderation_rest_resource_alter()
+ */
+ public function testCreateContentModerationStateResource() {
+ $this->setExpectedException(PluginNotFoundException::class, 'The "entity:content_moderation_state" plugin does not exist.');
+ RestResourceConfig::create([
+ 'id' => 'entity.content_moderation_state',
+ 'granularity' => RestResourceConfigInterface::RESOURCE_GRANULARITY,
+ 'configuration' => [
+ 'methods' => ['GET'],
+ 'formats' => ['json'],
+ 'authentication' => ['cookie'],
+ ],
+ ])
+ ->enable()
+ ->save();
+ }
+
+}