You are here

trait PdfTrait in PDF Generator 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/views/style/PdfTrait.php \Drupal\pdf_generator\Plugin\views\style\PdfTrait

This trait prevent duplicated code on every style.

Hierarchy

  • trait \Drupal\pdf_generator\Plugin\views\style\PdfTrait

File

src/Plugin/views/style/PdfTrait.php, line 10

Namespace

Drupal\pdf_generator\Plugin\views\style
View source
trait PdfTrait {

  /**
   * {@inheritdoc}
   */
  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,
    ];
  }

}

Members