Commit 5a9de4fc authored by alexpott's avatar alexpott
Browse files

Issue #2941622 by Wim Leers: Make REST's EntityResource deriver exclude...

Issue #2941622 by Wim Leers: Make REST's EntityResource deriver exclude internal entity types and mark ContentModerationState entity type as internal instead of the current hack
parent 0e564172
......@@ -319,13 +319,3 @@ function content_moderation_workflow_update(WorkflowInterface $entity) {
// Clear field cache so extra field is added or removed.
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
}
/**
* 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']);
}
......@@ -31,6 +31,7 @@
* data_table = "content_moderation_state_field_data",
* revision_data_table = "content_moderation_state_field_revision",
* translatable = TRUE,
* internal = TRUE,
* entity_keys = {
* "id" = "id",
* "revision" = "revision_id",
......
......@@ -18,7 +18,7 @@ class ContentModerationStateResourceTest extends KernelTestBase {
public static $modules = ['serialization', 'rest', 'content_moderation'];
/**
* @see content_moderation_rest_resource_alter()
* @see \Drupal\content_moderation\Entity\ContentModerationState
*/
public function testCreateContentModerationStateResource() {
$this->setExpectedException(PluginNotFoundException::class, 'The "entity:content_moderation_state" plugin does not exist.');
......
......@@ -65,6 +65,10 @@ public function getDerivativeDefinitions($base_plugin_definition) {
if (!isset($this->derivatives)) {
// Add in the default plugin configuration and the resource type.
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->isInternal()) {
continue;
}
$this->derivatives[$entity_type_id] = [
'id' => 'entity:' . $entity_type_id,
'entity_type' => $entity_type_id,
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\rest\Functional\EntityResource;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Tests\BrowserTestBase;
/**
......@@ -45,15 +46,11 @@ protected function setUp() {
$this->definitions = $this->container->get('entity_type.manager')->getDefinitions();
// Remove definitions for which the REST resource plugin definition was
// removed via hook_rest_resource_alter(). Entity types which are never
// exposed via REST also don't need test coverage.
$resource_plugin_ids = array_keys($this->container->get('plugin.manager.rest')->getDefinitions());
foreach (array_keys($this->definitions) as $entity_type_id) {
if (!in_array("entity:$entity_type_id", $resource_plugin_ids, TRUE)) {
unset($this->definitions[$entity_type_id]);
}
}
// Entity types marked as "internal" are not exposed by the entity REST
// resource plugin and hence also don't need test coverage.
$this->definitions = array_filter($this->definitions, function (EntityTypeInterface $entity_type) {
return !$entity_type->isInternal();
});
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment