X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Frest%2Fsrc%2FPlugin%2FResourceBase.php;fp=web%2Fcore%2Fmodules%2Frest%2Fsrc%2FPlugin%2FResourceBase.php;h=743674fdfd5516499ff9237b1d9d06805f4e0ee3;hp=b40a03109b0cc0a2424f442b9588ed0ed6686a6c;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/rest/src/Plugin/ResourceBase.php b/web/core/modules/rest/src/Plugin/ResourceBase.php index b40a03109..743674fdf 100644 --- a/web/core/modules/rest/src/Plugin/ResourceBase.php +++ b/web/core/modules/rest/src/Plugin/ResourceBase.php @@ -4,6 +4,7 @@ namespace Drupal\rest\Plugin; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; +use Drupal\Core\Routing\BcRoute; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Route; @@ -114,29 +115,24 @@ abstract class ResourceBase extends PluginBase implements ContainerFactoryPlugin $methods = $this->availableMethods(); foreach ($methods as $method) { - $route = $this->getBaseRoute($canonical_path, $method); - - switch ($method) { - case 'POST': - $route->setPath($create_path); - $collection->add("$route_name.$method", $route); - break; - - case 'GET': - case 'HEAD': - // Restrict GET and HEAD requests to the media type specified in the - // HTTP Accept headers. - foreach ($this->serializerFormats as $format_name) { - // Expose one route per available format. - $format_route = clone $route; - $format_route->addRequirements(['_format' => $format_name]); - $collection->add("$route_name.$method.$format_name", $format_route); - } - break; - - default: - $collection->add("$route_name.$method", $route); - break; + $path = $method === 'POST' + ? $create_path + : $canonical_path; + $route = $this->getBaseRoute($path, $method); + + // Note that '_format' and '_content_type_format' route requirements are + // added in ResourceRoutes::getRoutesForResourceConfig(). + $collection->add("$route_name.$method", $route); + + // BC: the REST module originally created per-format GET routes, instead + // of a single route. To minimize the surface of this BC layer, this uses + // route definitions that are as empty as possible, plus an outbound route + // processor. + // @see \Drupal\rest\RouteProcessor\RestResourceGetRouteProcessorBC + if ($method === 'GET' || $method === 'HEAD') { + foreach ($this->serializerFormats as $format_name) { + $collection->add("$route_name.$method.$format_name", (new BcRoute())->setRequirement('_format', $format_name)); + } } }