You are here

public function PrintInvoiceAction::execute in Ubercart 8.4

Executes the plugin.

Overrides ExecutableInterface::execute

File

uc_order/src/Plugin/Action/PrintInvoiceAction.php, line 67

Class

PrintInvoiceAction
Sets the response to a page that triggres the print dialog.

Namespace

Drupal\uc_order\Plugin\Action

Code

public function execute($order = NULL) {
  $build = [
    '#theme' => 'uc_order_invoice',
    '#order' => $order,
    '#op' => 'print',
    '#prefix' => '<div style="page-break-after: always;">',
    '#suffix' => '</div>',
  ];
  $output = '<html><head><title>Invoice</title></head>';
  $output .= '<body onload="print();">';
  $output .= drupal_render($build);
  $output .= '</body></html>';
  $response = new Response($output);
  $listener = function ($event) use ($response) {
    $event
      ->setResponse($response);
  };

  // Add the listener to the event dispatcher.
  $this->dispatcher
    ->addListener(KernelEvents::RESPONSE, $listener);
}