You are here

public static function OAIPMH::buildResponse in Views OAI-PMH 8

File

src/Plugin/views/display/OAIPMH.php, line 121

Class

OAIPMH
Plugin annotation @ViewsDisplay( id = "views_oai_pmh_display", title = @Translation("OAI-PMH Views"), help = @Translation("Provide a feed using the OAI-PMH protocol."), uses_route = TRUE, admin = @Translation("OAI-PMH Views"), …

Namespace

Drupal\views_oai_pmh\Plugin\views\display

Code

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

  // Setup an empty response so headers can be added as needed during views
  // rendering and processing.
  $response = new CacheableResponse('', 200);
  $build['#response'] = $response;

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');
  $output = (string) $renderer
    ->renderRoot($build);
  $response
    ->setContent($output);
  $cache_metadata = CacheableMetadata::createFromRenderArray($build);
  $response
    ->addCacheableDependency($cache_metadata);
  $response->headers
    ->set('Content-Type', 'application/xml;charset=UTF-8');
  return $response;
}