core/modules/rest/src/Plugin/ResourceBase.php | 5 ++++- core/modules/rest/src/Routing/ResourceRoutes.php | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/modules/rest/src/Plugin/ResourceBase.php b/core/modules/rest/src/Plugin/ResourceBase.php index a3ea800..60d2cdb 100644 --- a/core/modules/rest/src/Plugin/ResourceBase.php +++ b/core/modules/rest/src/Plugin/ResourceBase.php @@ -130,7 +130,10 @@ public function routes() { // @see \Drupal\rest\RouteProcessor\RestResourceGetRouteProcessorBC if ($method === 'GET' || $method === 'HEAD') { foreach ($this->serializerFormats as $format_name) { - $collection->add("$route_name.$method.$format_name", (new Route(''))->setOption('bc_route', TRUE)); + $collection->add("$route_name.$method.$format_name", (new Route('')) + ->setRequirement('_format', $format_name) + ->setOption('bc_route', TRUE) + ); } } } diff --git a/core/modules/rest/src/Routing/ResourceRoutes.php b/core/modules/rest/src/Routing/ResourceRoutes.php index e9d5437..0c616ef 100644 --- a/core/modules/rest/src/Routing/ResourceRoutes.php +++ b/core/modules/rest/src/Routing/ResourceRoutes.php @@ -110,6 +110,14 @@ protected function getRoutesForResourceConfig(RestResourceConfigInterface $rest_ continue; } + // Remove BC routes for unsupported formats. + if ($route->getOption('bc_route') === TRUE) { + $format_requirement = $route->getRequirement('_format'); + if ($format_requirement && !in_array($format_requirement, $rest_resource_config->getFormats($method))) { + continue; + } + } + // The configuration has been validated, so we update the route to: // - set the allowed response body content types/formats for methods // that may send response bodies