public function InvoiceController::download in Commerce Invoice 8.2
Download an invoice.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.
Return value
\Symfony\Component\HttpFoundation\Response The response.
Throws
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException Thrown when the file was not found.
File
- src/
Controller/ InvoiceController.php, line 133
Class
- InvoiceController
- Provides the invoice download route.
Namespace
Drupal\commerce_invoice\ControllerCode
public function download(RouteMatchInterface $route_match) {
/** @var \Drupal\commerce_invoice\Entity\InvoiceInterface $invoice */
$invoice = $route_match
->getParameter('commerce_invoice');
$file = $this->invoiceFileManager
->getInvoiceFile($invoice);
$config = $this->configFactory
->get('entity_print.settings');
// Check whether we need to force the download.
$content_disposition = $config
->get('force_download') ? 'attachment' : NULL;
$headers = file_get_content_headers($file);
return new BinaryFileResponse($file
->getFileUri(), 200, $headers, FALSE, $content_disposition);
}