public static function ExcelExport::buildResponse in Excel Serialization 8
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 RestExport::buildResponse
File
- src/
Plugin/ views/ display/ ExcelExport.php, line 39
Class
- ExcelExport
- Provides an Excel export display plugin.
Namespace
Drupal\xls_serialization\Plugin\views\displayCode
public static function buildResponse($view_id, $display_id, array $args = []) {
// Do not call the parent method, as it makes the response harder to alter.
// @see https://www.drupal.org/node/2779807
$build = static::buildBasicRenderable($view_id, $display_id, $args);
// Setup an empty response, so for example, the Content-Disposition header
// can be set.
$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;
}