You are here

public function MonitoringSensorResultResource::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

src/Plugin/rest/resource/MonitoringSensorResultResource.php, line 80
Definition of Drupal\monitoring\Plugin\rest\resource\MonitoringSensorInfoResource.

Class

MonitoringSensorResultResource
Provides a resource for monitoring sensors results.

Namespace

Drupal\monitoring\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;
}