Returns a collection of routes with URL path information for the resource.
This method determines where a resource is reachable, what path replacements are used, the required HTTP method for the operation etc.
\Symfony\Component\Routing\RouteCollection A collection of routes that should be registered for this resource.
public function routes() {
$collection = new RouteCollection();
$methods = $this
->requestMethods();
foreach ($methods as $method) {
$lower_method = strtolower($method);
// Only expose routes where the HTTP request method exists on the plugin.
if (method_exists($this, $lower_method)) {
$prefix = strtr($this->plugin_id, ':', '/');
$route = new Route("/{$prefix}/{id}", array(
'_controller' => 'Drupal\\rest\\RequestHandler::handle',
// @todo Once http://drupal.org/node/1793520 is committed we will have
// route object avaialble in the controller so 'plugin' property
// should be changed to '_plugin'.
// @see RequestHandler::handle().
'plugin' => $this->plugin_id,
), array(
// The HTTP method is a requirement for this route.
'_method' => $method,
'_permission' => "restful {$lower_method} {$this->plugin_id}",
));
$name = strtr($this->plugin_id, ':', '.');
$collection
->add("{$name}.{$method}", $route);
}
}
return $collection;
}