Mercurial > hg > isophonics-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
2 | 2 |
3 namespace Drupal\rest\Plugin; | 3 namespace Drupal\rest\Plugin; |
4 | 4 |
5 use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | 5 use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
6 use Drupal\Core\Plugin\PluginBase; | 6 use Drupal\Core\Plugin\PluginBase; |
7 use Drupal\Core\Routing\BcRoute; | |
7 use Psr\Log\LoggerInterface; | 8 use Psr\Log\LoggerInterface; |
8 use Symfony\Component\DependencyInjection\ContainerInterface; | 9 use Symfony\Component\DependencyInjection\ContainerInterface; |
9 use Symfony\Component\Routing\Route; | 10 use Symfony\Component\Routing\Route; |
10 use Symfony\Component\Routing\RouteCollection; | 11 use Symfony\Component\Routing\RouteCollection; |
11 | 12 |
112 | 113 |
113 $route_name = strtr($this->pluginId, ':', '.'); | 114 $route_name = strtr($this->pluginId, ':', '.'); |
114 | 115 |
115 $methods = $this->availableMethods(); | 116 $methods = $this->availableMethods(); |
116 foreach ($methods as $method) { | 117 foreach ($methods as $method) { |
117 $route = $this->getBaseRoute($canonical_path, $method); | 118 $path = $method === 'POST' |
118 | 119 ? $create_path |
119 switch ($method) { | 120 : $canonical_path; |
120 case 'POST': | 121 $route = $this->getBaseRoute($path, $method); |
121 $route->setPath($create_path); | 122 |
122 $collection->add("$route_name.$method", $route); | 123 // Note that '_format' and '_content_type_format' route requirements are |
123 break; | 124 // added in ResourceRoutes::getRoutesForResourceConfig(). |
124 | 125 $collection->add("$route_name.$method", $route); |
125 case 'GET': | 126 |
126 case 'HEAD': | 127 // BC: the REST module originally created per-format GET routes, instead |
127 // Restrict GET and HEAD requests to the media type specified in the | 128 // of a single route. To minimize the surface of this BC layer, this uses |
128 // HTTP Accept headers. | 129 // route definitions that are as empty as possible, plus an outbound route |
129 foreach ($this->serializerFormats as $format_name) { | 130 // processor. |
130 // Expose one route per available format. | 131 // @see \Drupal\rest\RouteProcessor\RestResourceGetRouteProcessorBC |
131 $format_route = clone $route; | 132 if ($method === 'GET' || $method === 'HEAD') { |
132 $format_route->addRequirements(['_format' => $format_name]); | 133 foreach ($this->serializerFormats as $format_name) { |
133 $collection->add("$route_name.$method.$format_name", $format_route); | 134 $collection->add("$route_name.$method.$format_name", (new BcRoute())->setRequirement('_format', $format_name)); |
134 } | 135 } |
135 break; | |
136 | |
137 default: | |
138 $collection->add("$route_name.$method", $route); | |
139 break; | |
140 } | 136 } |
141 } | 137 } |
142 | 138 |
143 return $collection; | 139 return $collection; |
144 } | 140 } |