class InvoicePrintBuilder in Commerce Invoice 8.2
The print builder service.
Hierarchy
- class \Drupal\commerce_invoice\InvoicePrintBuilder implements InvoicePrintBuilderInterface
Expanded class hierarchy of InvoicePrintBuilder
1 string reference to 'InvoicePrintBuilder'
1 service uses InvoicePrintBuilder
File
- src/
InvoicePrintBuilder.php, line 19
Namespace
Drupal\commerce_invoiceView source
class InvoicePrintBuilder implements InvoicePrintBuilderInterface {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The entity storage for the 'file' entity type.
*
* @var \Drupal\file\FileStorageInterface
*/
protected $fileStorage;
/**
* The Entity print builder.
*
* @var \Drupal\entity_print\PrintBuilderInterface
*/
protected $printBuilder;
/**
* The Entity print filename generator.
*
* @var \Drupal\entity_print\FilenameGeneratorInterface
*/
protected $filenameGenerator;
/**
* The event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* The Current User object.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructs a new InvoicePrintBuilder object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\entity_print\PrintBuilderInterface $print_builder
* The Entity print builder.
* @param \Drupal\entity_print\FilenameGeneratorInterface $filename_generator
* The Entity print filename generator.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, PrintBuilderInterface $print_builder, FilenameGeneratorInterface $filename_generator, EventDispatcherInterface $event_dispatcher, AccountInterface $current_user) {
$this->configFactory = $config_factory;
$this->fileStorage = $entity_type_manager
->getStorage('file');
$this->printBuilder = $print_builder;
$this->filenameGenerator = $filename_generator;
$this->eventDispatcher = $event_dispatcher;
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public function generateFilename(InvoiceInterface $invoice) {
$filename = $this->filenameGenerator
->generateFilename([
$invoice,
]);
$filename .= '-' . $invoice
->language()
->getId() . '-' . str_replace('_', '', $invoice
->getState()
->getId());
// Let the filename be altered.
$event = new InvoiceFilenameEvent($filename, $invoice);
$this->eventDispatcher
->dispatch(InvoiceEvents::INVOICE_FILENAME, $event);
$filename = $event
->getFilename() . '.pdf';
return $filename;
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InvoicePrintBuilder:: |
protected | property | The config factory. | |
InvoicePrintBuilder:: |
protected | property | The Current User object. | |
InvoicePrintBuilder:: |
protected | property | The event dispatcher. | |
InvoicePrintBuilder:: |
protected | property | The Entity print filename generator. | |
InvoicePrintBuilder:: |
protected | property | The entity storage for the 'file' entity type. | |
InvoicePrintBuilder:: |
protected | property | The Entity print builder. | |
InvoicePrintBuilder:: |
public | function |
Generates a filename for the given invoice. Overrides InvoicePrintBuilderInterface:: |
|
InvoicePrintBuilder:: |
public | function |
Renders the invoice as a printed document and save to disk. Overrides InvoicePrintBuilderInterface:: |
|
InvoicePrintBuilder:: |
public | function | Constructs a new InvoicePrintBuilder object. |