public function PdfTrait::attachTo in PDF Generator 8
Same name and namespace in other branches
- 2.0.x src/Plugin/views/style/PdfTrait.php \Drupal\pdf_generator\Plugin\views\style\PdfTrait::attachTo()
File
- src/
Plugin/ views/ style/ PdfTrait.php, line 15
Class
- PdfTrait
- This trait prevent duplicated code on every style.
Namespace
Drupal\pdf_generator\Plugin\views\styleCode
public function attachTo(array &$build, $display_id, Url $url, $title) {
$url_options = [];
$input = $this->view
->getExposedInput();
if ($input) {
$url_options['query'] = $input;
}
$url_options['absolute'] = TRUE;
if (!empty($this->options['formats'])) {
$url_options['query']['_format'] = reset($this->options['formats']);
}
$url = $url
->setOptions($url_options)
->toString();
$this->view->feedIcons[] = [
'#theme' => 'pdf_generator_feed_icon',
'#url' => $url,
'#title' => $title,
'#theme_wrappers' => [
'container' => [
'#attributes' => [
'class' => [
'pdf-feed',
'pdf-generator-feed',
],
],
],
],
'#attached' => [
'library' => [
'pdf_generator/pdf_generator',
],
],
];
// Attach a link to the CSV feed, which is an alternate representation.
$build['#attached']['html_head_link'][][] = [
'rel' => 'alternate',
'type' => 'application/pdf',
'title' => $title,
'href' => $url,
];
}