You are here

public static function RestExport::buildResponse 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::buildResponse()

Builds up a response with the rendered view as content.

Parameters

string $view_id: The view ID.

string $display_id: The display ID.

array $args: (optional) The arguments of the view.

Return value

\Symfony\Component\HttpFoundation\Response The built response.

Overrides ResponseDisplayPluginInterface::buildResponse

File

core/modules/rest/src/Plugin/views/display/RestExport.php, line 282
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 static function buildResponse($view_id, $display_id, array $args = []) {
  $build = static::buildBasicRenderable($view_id, $display_id, $args);

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');
  $output = $renderer
    ->renderRoot($build);
  $response = new CacheableResponse($output, 200);
  $cache_metadata = CacheableMetadata::createFromRenderArray($build);
  $response
    ->addCacheableDependency($cache_metadata);
  $response->headers
    ->set('Content-type', $build['#content_type']);
  return $response;
}