Mercurial > hg > isophonics-drupal-site
diff core/modules/rest/src/Plugin/ResourceBase.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/core/modules/rest/src/Plugin/ResourceBase.php Mon Apr 23 09:33:26 2018 +0100 +++ b/core/modules/rest/src/Plugin/ResourceBase.php Mon Apr 23 09:46:53 2018 +0100 @@ -4,6 +4,7 @@ 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 @@ $methods = $this->availableMethods(); foreach ($methods as $method) { - $route = $this->getBaseRoute($canonical_path, $method); + $path = $method === 'POST' + ? $create_path + : $canonical_path; + $route = $this->getBaseRoute($path, $method); - switch ($method) { - case 'POST': - $route->setPath($create_path); - $collection->add("$route_name.$method", $route); - break; + // Note that '_format' and '_content_type_format' route requirements are + // added in ResourceRoutes::getRoutesForResourceConfig(). + $collection->add("$route_name.$method", $route); - 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; + // 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)); + } } }