You are here

public function RestExport::collectRoutes in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/rest/src/Plugin/views/display/RestExport.php \Drupal\rest\Plugin\views\display\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

core/modules/rest/src/Plugin/views/display/RestExport.php, line 258
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);
  $view_id = $this->view->storage
    ->id();
  $display_id = $this->display['id'];
  if ($route = $collection
    ->get("view.{$view_id}.{$display_id}")) {
    $style_plugin = $this
      ->getPlugin('style');

    // REST exports should only respond to get methods.
    $route
      ->setMethods([
      'GET',
    ]);

    // Format as a string using pipes as a delimiter.
    if ($formats = $style_plugin
      ->getFormats()) {

      // Allow a REST Export View to be returned with an HTML-only accept
      // format. That allows browsers or other non-compliant systems to access
      // the view, as it is unlikely to have a conflicting HTML representation
      // anyway.
      $route
        ->setRequirement('_format', implode('|', $formats + [
        'html',
      ]));
    }
  }
}