summaryrefslogtreecommitdiffstats
path: root/core/modules/rest/src/Plugin/ResourceBase.php
diff options
context:
space:
mode:
authorNathaniel Catchpole2014-06-20 17:38:26 (GMT)
committerNathaniel Catchpole2014-06-20 17:38:26 (GMT)
commit0f752ca6091259af20300ef8d156caa1daea6088 (patch)
treeb64586c2014bd541846c054738f898e148e52e32 /core/modules/rest/src/Plugin/ResourceBase.php
parenta4d7fad2ae091d4206f22ab427159657ca90b9a5 (diff)
Issue #1906810 by dawehner, damiankloip, tstoeckler, kgoel, fubhy, jrglasgow, xjm, Gaelan, socketwench: Require type hints for automatic entity upcasting.
Diffstat (limited to 'core/modules/rest/src/Plugin/ResourceBase.php')
-rw-r--r--core/modules/rest/src/Plugin/ResourceBase.php41
1 files changed, 29 insertions, 12 deletions
diff --git a/core/modules/rest/src/Plugin/ResourceBase.php b/core/modules/rest/src/Plugin/ResourceBase.php
index e54e134..05c0a2d 100644
--- a/core/modules/rest/src/Plugin/ResourceBase.php
+++ b/core/modules/rest/src/Plugin/ResourceBase.php
@@ -87,18 +87,7 @@ abstract class ResourceBase extends PluginBase implements ContainerFactoryPlugin
$methods = $this->availableMethods();
foreach ($methods as $method) {
- $lower_method = strtolower($method);
- $route = new Route($canonical_path, array(
- '_controller' => 'Drupal\rest\RequestHandler::handle',
- // Pass the resource plugin ID along as default property.
- '_plugin' => $this->pluginId,
- ), array(
- // The HTTP method is a requirement for this route.
- '_method' => $method,
- '_permission' => "restful $lower_method $this->pluginId",
- ), array(
- '_access_mode' => 'ANY',
- ));
+ $route = $this->getBaseRoute($canonical_path, $method);
switch ($method) {
case 'POST':
@@ -175,4 +164,32 @@ abstract class ResourceBase extends PluginBase implements ContainerFactoryPlugin
return $available;
}
+ /**
+ * Setups the base route for all HTTP methods.
+ *
+ * @param string $canonical_path
+ * The canonical path for the resource.
+ * @param string $method
+ * The HTTP method to be used for the route.
+ *
+ * @return \Symfony\Component\Routing\Route
+ * The created base route.
+ */
+ protected function getBaseRoute($canonical_path, $method) {
+ $lower_method = strtolower($method);
+
+ $route = new Route($canonical_path, array(
+ '_controller' => 'Drupal\rest\RequestHandler::handle',
+ // Pass the resource plugin ID along as default property.
+ '_plugin' => $this->pluginId,
+ ), array(
+ // The HTTP method is a requirement for this route.
+ '_method' => $method,
+ '_permission' => "restful $lower_method $this->pluginId",
+ ), array(
+ '_access_mode' => 'ANY',
+ ));
+ return $route;
+ }
+
}