You are here

public function MonitoringMultigraphResource::routes in Monitoring 8

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.

Return value

\Symfony\Component\Routing\RouteCollection A collection of routes that should be registered for this resource.

Overrides ResourceBase::routes

File

modules/multigraph/src/Plugin/rest/resource/MonitoringMultigraphResource.php, line 30
Contains \Drupal\monitoring_multigraph\Plugin\rest\resource\MonitoringMultigraphResource.

Class

MonitoringMultigraphResource
Provides a resource for monitoring multigraphs.

Namespace

Drupal\monitoring_multigraph\Plugin\rest\resource

Code

public function routes() {
  $path_prefix = strtr($this->pluginId, ':', '/');
  $route_name = strtr($this->pluginId, ':', '.');
  $collection = parent::routes();
  $route = new Route("/{$path_prefix}", array(
    '_controller' => 'Drupal\\rest\\RequestHandler::handle',
    // Pass the resource plugin ID along as default property.
    '_plugin' => $this->pluginId,
  ), array(
    '_permission' => "restful get {$this->pluginId}",
  ));
  $route
    ->setMethods([
    'GET',
  ]);
  foreach ($this->serializerFormats as $format_name) {

    // Expose one route per available format.
    $format_route = clone $route;
    $format_route
      ->addRequirements(array(
      '_format' => $format_name,
    ));
    $collection
      ->add("{$route_name}.list.{$format_name}", $format_route);
  }
  return $collection;
}