class InvoiceConfirmationMail in Commerce Invoice 8.2
Hierarchy
- class \Drupal\commerce_invoice\Mail\InvoiceConfirmationMail implements InvoiceConfirmationMailInterface uses StringTranslationTrait
Expanded class hierarchy of InvoiceConfirmationMail
1 string reference to 'InvoiceConfirmationMail'
1 service uses InvoiceConfirmationMail
File
- src/
Mail/ InvoiceConfirmationMail.php, line 12
Namespace
Drupal\commerce_invoice\MailView source
class InvoiceConfirmationMail implements InvoiceConfirmationMailInterface {
use StringTranslationTrait;
/**
* The mail handler.
*
* @var \Drupal\commerce\MailHandlerInterface
*/
protected $mailHandler;
/**
* The invoice total summary.
*
* @var \Drupal\commerce_invoice\InvoiceTotalSummaryInterface
*/
protected $invoiceTotalSummary;
/**
* The profile view builder.
*
* @var \Drupal\profile\ProfileViewBuilder
*/
protected $profileViewBuilder;
/**
* The invoice file manager.
*
* @var \Drupal\commerce_invoice\InvoiceFileManagerInterface
*/
protected $invoiceFileManager;
/**
* Constructs a new InvoiceConfirmationMail object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\commerce\MailHandlerInterface $mail_handler
* The mail handler.
* @param \Drupal\commerce_invoice\InvoiceTotalSummaryInterface $invoice_total_summary
* The invoice total summary.
* @param \Drupal\commerce_invoice\InvoiceFileManagerInterface $invoice_file_manager
* The invoice file manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, MailHandlerInterface $mail_handler, InvoiceTotalSummaryInterface $invoice_total_summary, InvoiceFileManagerInterface $invoice_file_manager) {
$this->mailHandler = $mail_handler;
$this->invoiceTotalSummary = $invoice_total_summary;
$this->profileViewBuilder = $entity_type_manager
->getViewBuilder('profile');
$this->invoiceFileManager = $invoice_file_manager;
}
/**
* {@inheritdoc}
*/
public function send(InvoiceInterface $invoice, $to = NULL, $bcc = NULL) {
$to = isset($to) ? $to : $invoice
->getEmail();
if (!$to) {
// The email should not be empty.
return FALSE;
}
$subject = $this
->t('Invoice #@number', [
'@number' => $invoice
->getInvoiceNumber(),
]);
$body = [
'#theme' => 'commerce_invoice_confirmation',
'#invoice_entity' => $invoice,
'#totals' => $this->invoiceTotalSummary
->buildTotals($invoice),
];
if ($billing_profile = $invoice
->getBillingProfile()) {
$body['#billing_information'] = $this->profileViewBuilder
->view($billing_profile);
}
$params = [
'id' => 'invoice_confirmation',
'from' => $invoice
->getStore()
->getEmail(),
'bcc' => $bcc,
'invoice' => $invoice,
];
$customer = $invoice
->getCustomer();
if ($customer
->isAuthenticated()) {
$params['langcode'] = $customer
->getPreferredLangcode();
}
$file = $this->invoiceFileManager
->getInvoiceFile($invoice);
$attachment = [
'filepath' => $file
->getFileUri(),
'filename' => $file
->getFilename(),
'filemime' => $file
->getMimeType(),
];
$params['attachments'][] = $attachment;
return $this->mailHandler
->sendMail($to, $subject, $body, $params);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InvoiceConfirmationMail:: |
protected | property | The invoice file manager. | |
InvoiceConfirmationMail:: |
protected | property | The invoice total summary. | |
InvoiceConfirmationMail:: |
protected | property | The mail handler. | |
InvoiceConfirmationMail:: |
protected | property | The profile view builder. | |
InvoiceConfirmationMail:: |
public | function |
Sends the invoice confirmation email. Overrides InvoiceConfirmationMailInterface:: |
|
InvoiceConfirmationMail:: |
public | function | Constructs a new InvoiceConfirmationMail object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |