Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 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;
 }
Ejemplo n.º 2
0
 /**
  * Sets a header.
  */
 public function setHeader(Request $request)
 {
     $query = $request->query->all();
     $response = new CacheableResponse();
     $response->headers->set($query['name'], $query['value']);
     $response->getCacheableMetadata()->addCacheContexts(['url.query_args:name', 'url.query_args:value']);
     $response->setContent($this->t('The following header was set: %name: %value', array('%name' => $query['name'], '%value' => $query['value'])));
     return $response;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 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', $build['#content_type']);
     return $response;
 }