function RestExport::collectRoutes

Same name in other branches
  1. 9 core/modules/rest/src/Plugin/views/display/RestExport.php \Drupal\rest\Plugin\views\display\RestExport::collectRoutes()
  2. 8.9.x core/modules/rest/src/Plugin/views/display/RestExport.php \Drupal\rest\Plugin\views\display\RestExport::collectRoutes()
  3. 11.x core/modules/rest/src/Plugin/views/display/RestExport.php \Drupal\rest\Plugin\views\display\RestExport::collectRoutes()

Overrides PathPluginBase::collectRoutes

File

core/modules/rest/src/Plugin/views/display/RestExport.php, line 342

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',
        ]);
        $formats = $style_plugin->getFormats();
        // If there are no configured formats, add all formats that serialization
        // is known to support.
        if (!$formats) {
            $formats = $this->getFormatOptions();
        }
        // Format as a string using pipes as a delimiter.
        $route->setRequirement('_format', implode('|', $formats));
        // Add authentication to the route if it was set. If no authentication was
        // set, the default authentication will be used, which is cookie based by
        // default.
        $auth = $this->getOption('auth');
        if (!empty($auth)) {
            $route->setOption('_auth', $auth);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.