Commit 21bc9f74 authored by Pedro Cambra's avatar Pedro Cambra Committed by Pedro Cambra
Browse files

Issue #3294175 by pcambra: When using the resend ticket receipt, the PDF is...

Issue #3294175 by pcambra: When using the resend ticket receipt, the PDF is downloaded automatically and there's no attachment
parent 8c77241e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -24,3 +24,10 @@ services:
    arguments: ['@entity_type.manager', '@entity.repository']
    tags:
      - { name: paramconverter }

  commerce_ticketing.print_builder:
    class: Drupal\commerce_ticketing\PrintBuilder
    decorates: entity_print.print_builder
    decoration_priority: 1
    public: false
    arguments: ['@entity_print.renderer_factory', '@event_dispatcher', '@string_translation']
+3 −7
Original line number Diff line number Diff line
@@ -151,18 +151,14 @@ class TicketReceiptMail {
      $print_engine = $this->pluginManager->createSelectedInstance('pdf');
      $config = $this->configFactory->get('entity_print.settings');

      // We need to switch accounts to the customer so we can print the ticket
      // We need to switch accounts to the customer, so we can print the ticket
      // as if we were the user, otherwise it might try to print as anonymous
      // and show blank tickets.
      $this->accountSwitcher->switchTo($customer);

      // PDF generation inline so we don't have to deal with files.
      ob_start();
      (new StreamedResponse(function () use ($ticket, $print_engine, $config) {
        $this->printBuilder->deliverPrintable([$ticket], $print_engine, FALSE, $config->get('default_css'));
      }))->send();
      $contents = ob_get_contents();
      ob_end_clean();
      $contents = $this->printBuilder->deliverPrintableForMail([$ticket], $print_engine, $config->get('default_css'));

      $this->accountSwitcher->switchBack();

      $params['attachment'] = [

src/PrintBuilder.php

0 → 100644
+21 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\commerce_ticketing;

use Drupal\entity_print\Plugin\PrintEngineInterface;
use Drupal\entity_print\PrintBuilder as EntityPrintPrintBuilder;

/**
 * The print builder service.
 */
class PrintBuilder extends EntityPrintPrintBuilder {

  /**
   * {@inheritdoc}
   */
  public function deliverPrintableforMail(array $entities, PrintEngineInterface $print_engine, $use_default_css = TRUE) {
    $this->prepareRenderer($entities, $print_engine, $use_default_css);
    return $print_engine->getBlob();
  }

}