You are here

function commerce_invoice_mail_pdf_prepare in Commerce Invoice 7.2

Helper function to prepare the invoice mail.

Parameters

Invoice $invoice Invoice object.:

Return value

array Email attachments.

1 call to commerce_invoice_mail_pdf_prepare()
commerce_invoice_mail_send in modules/mail/commerce_invoice_mail.module

File

modules/mail/commerce_invoice_mail.module, line 85
The Commerce Invoice PDF module.

Code

function commerce_invoice_mail_pdf_prepare(Invoice $invoice) {
  if (module_exists('commerce_invoice_pdf')) {
    module_load_include('module', 'commerce_invoice_pdf');
  }
  else {
    drupal_set_message(t('PDF email attachment could not be created, because commerce_invoice_pdf is disabled.'), 'error');
    return [];
  }
  $file = commerce_invoice_pdf_create($invoice);
  $file_content = file_get_contents(drupal_realpath($file->uri));
  $attachments = [];
  $attachments[] = array(
    'filecontent' => $file_content,
    // we use a dynamically created file.
    'filename' => $file->filename,
    // can use any alias name here
    'name' => $file->filename,
    // required for mandril and other libraries.
    'filemime' => $file->filemime,
    // mime file type
    'type' => $file->filemime,
    // required for mandril and other libraries
    'list' => TRUE,
  );
  return $attachments;
}