public function RestExport::collectRoutes

Adds the route entry of a view to the collection.

Parameters

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

Overrides PathPluginBase::collectRoutes

File

drupal/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php, line 208
Contains \Drupal\rest\Plugin\views\display\RestExport.

Class

RestExport
The plugin that handles Data response callbacks for REST resources.

Namespace

Drupal\rest\Plugin\views\display

Code

public function collectRoutes(RouteCollection $collection) {
  parent::collectRoutes($collection);
  $style_plugin = $this
    ->getPlugin('style');

  // REST exports should only respond to get methods.
  $requirements = array(
    '_method' => 'GET',
  );

  // Format as a string using pipes as a delimeter.
  $requirements['_format'] = implode('|', $style_plugin
    ->getFormats());

  // Add the new requirements to each route.
  foreach ($collection as $route) {
    $route
      ->addRequirements($requirements);
  }
}