core/modules/media/media.module | 16 ++++++++ .../tests/src/Functional/MediaResourceTest.php | 47 ++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/core/modules/media/media.module b/core/modules/media/media.module index eeb2ac1..9faf7c8 100644 --- a/core/modules/media/media.module +++ b/core/modules/media/media.module @@ -48,6 +48,22 @@ function media_theme() { } /** + * Implements hook_rest_resource_alter(). + * + * The normalization of Media and Media Type entities was never considered + * during their development. Rather than allowing them to fall back to defaults + * for their normalizations (and hence serializations), this excludes them from + * being exposed as REST resources. This is done to ensure we don't let clients + * be developed against the default normalizations, which are known to contain + * gaps especially for file handling, and hence are guaranteed to break BC. + * + * @todo Remove this in https://www.drupal.org/node/2895573 + */ +function media_rest_resource_alter(&$definitions) { + unset($definitions['entity:media'], $definitions['entity:media_type']); +} + +/** * Implements hook_entity_operation_alter(). * * Fix broken operations array in field UI for entities with restricted access. diff --git a/core/modules/media/tests/src/Functional/MediaResourceTest.php b/core/modules/media/tests/src/Functional/MediaResourceTest.php new file mode 100644 index 0000000..8e57306 --- /dev/null +++ b/core/modules/media/tests/src/Functional/MediaResourceTest.php @@ -0,0 +1,47 @@ +setExpectedException(PluginNotFoundException::class, 'The "entity:' . $entity_type_id . '" plugin does not exist.'); + RestResourceConfig::create([ + 'id' => 'entity.' . $entity_type_id, + 'granularity' => RestResourceConfigInterface::RESOURCE_GRANULARITY, + 'configuration' => [ + 'methods' => ['GET'], + 'formats' => ['json'], + 'authentication' => ['cookie'], + ], + ]) + ->enable() + ->save(); + } + + public function providerTestEnableMediaEntityType() { + return [ + ['media'], + ['media_type'], + ]; + } + +}