public static function Pdf::buildResponse in PDF Generator 8
Same name and namespace in other branches
- 2.0.x src/Plugin/views/display/Pdf.php \Drupal\pdf_generator\Plugin\views\display\Pdf::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
- src/
Plugin/ views/ display/ Pdf.php, line 100
Class
- The plugin that handles a feed, such as RSS or atom.
Namespace
Drupal\pdf_generator\Plugin\views\displayCode
public static function buildResponse($view_id, $display_id, array $args = []) {
$build = static::buildBasicRenderable($view_id, $display_id, $args);
$view = Views::getView($view_id);
$view
->setDisplay($display_id);
$renderer = \Drupal::service('renderer');
$output = [
'#markup' => (string) $renderer
->renderRoot($build),
];
if ($view->display_handler
->getOption('sitename_title') === 1) {
$config = \Drupal::config('system.site');
$titleValue = $config
->get('name');
}
elseif ($view->display_handler
->getOption('field_title') === 1) {
$fieldName = $view->display_handler
->getOption('select_field_title');
$entityTypeManager = \Drupal::entityTypeManager();
$node = $entityTypeManager
->getStorage('node')
->load(reset($args));
$titleValue = $node
->get($fieldName)->value;
}
else {
$titleValue = $view
->getTitle();
}
$title = [
'#markup' => $titleValue,
'#allowed_tags' => Xss::getHtmlTagList(),
];
$pageSize = !empty($view->display_handler
->getOption('paper_size')) ? $view->display_handler
->getOption('paper_size') : 'a4';
$disposition = !empty($view->display_handler
->getOption('paper_disposition')) ? $view->display_handler
->getOption('paper_disposition') : 'portrait';
$textCss = !empty($view->display_handler
->getOption('inline_css')) ? $view->display_handler
->getOption('inline_css') : NULL;
$fileCss = !empty($view->display_handler
->getOption('file_css')) ? $view->display_handler
->getOption('file_css') : NULL;
$response = \Drupal::service('pdf_generator.dompdf_generator')
->getResponse($title, $output, FALSE, [], $pageSize, $disposition, $textCss, $fileCss);
return $response;
}