public function InvoicePrintBuilder::savePrintable in Commerce Invoice 8.2
Renders the invoice as a printed document and save to disk.
Parameters
\Drupal\commerce_invoice\Entity\InvoiceInterface $invoice: The invoice.
\Drupal\entity_print\Plugin\PrintEngineInterface $print_engine: The print engine plugin to use.
string $scheme: (optional) The Drupal scheme, defaults to 'private'.
Return value
\Drupal\file\FileInterface|null The invoice PDF file, FALSE it could not be created.
Overrides InvoicePrintBuilderInterface::savePrintable
File
- src/
InvoicePrintBuilder.php, line 104
Class
- InvoicePrintBuilder
- The print builder service.
Namespace
Drupal\commerce_invoiceCode
public function savePrintable(InvoiceInterface $invoice, PrintEngineInterface $print_engine, $scheme = 'private') {
$filename = $this
->generateFilename($invoice);
$config = $this->configFactory
->get('entity_print.settings');
$uri = $this->printBuilder
->savePrintable([
$invoice,
], $print_engine, $scheme, $filename, $config
->get('default_css'));
if (!$uri) {
return FALSE;
}
$file = $this->fileStorage
->create([
'uri' => $uri,
'uid' => $this->currentUser
->id(),
'langcode' => $invoice
->language()
->getId(),
'status' => FILE_STATUS_PERMANENT,
]);
$file
->save();
return $file;
}