You are here

public static function Feed::buildResponse in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/display/Feed.php \Drupal\views\Plugin\views\display\Feed::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/views/src/Plugin/views/display/Feed.php, line 57
Contains \Drupal\views\Plugin\views\display\Feed.

Class

Feed
The plugin that handles a feed, such as RSS or atom.

Namespace

Drupal\views\Plugin\views\display

Code

public static function buildResponse($view_id, $display_id, array $args = []) {
  $build = static::buildBasicRenderable($view_id, $display_id, $args);

  // Set up an empty response, so for example RSS can set the proper
  // Content-Type header.
  $response = new CacheableResponse('', 200);
  $build['#response'] = $response;

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');
  $output = (string) $renderer
    ->renderRoot($build);
  if (empty($output)) {
    throw new NotFoundHttpException();
  }
  $response
    ->setContent($output);
  $cache_metadata = CacheableMetadata::createFromRenderArray($build);
  $response
    ->addCacheableDependency($cache_metadata);
  return $response;
}