commerce_billy_mail_attachment.module in Commerce Billy Mail 7
Commerce Billy Mail Attachment module file.
File
modules/commerce_billy_mail_attachment/commerce_billy_mail_attachment.moduleView source
<?php
/**
* @file
* Commerce Billy Mail Attachment module file.
*/
/**
* Implements hook_menu().
*/
function commerce_billy_mail_attachment_menu() {
$items['admin/commerce/config/billy-invoice/mail-attachment'] = array(
'title' => 'Mail attachments',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'commerce_billy_mail_attachment_admin_form',
),
'access arguments' => array(
'configure order settings',
),
'type' => MENU_LOCAL_TASK,
'file' => 'commerce_billy_mail_attachment.admin.inc',
'weight' => 10,
);
return $items;
}
/**
* Implements hook_mail_alter().
*/
function commerce_billy_mail_attachment_mail_alter(&$message) {
if ($message['id'] == 'commerce_billy_mail_commerce_billy_send_order_invoice') {
$settings = variable_get('commerce_billy_mail_attachment_fids', array());
foreach ($settings as $fid) {
$message['params']['attachments'][] = _commerce_billy_mail_attachment_get_attachment($fid);
}
}
}
/**
* Returns the mail attachment(s).
*
* @param int $fid
* @return array $attachment
*/
function _commerce_billy_mail_attachment_get_attachment($fid) {
$file = file_load($fid);
$realpath = drupal_realpath($file->uri);
$filecontent = file_get_contents($realpath);
$attachment = array(
'filecontent' => $filecontent,
'filename' => $file->filename,
'name' => $file->filename,
'filemime' => $file->filemime,
'type' => $file->filemime,
'list' => TRUE,
);
return $attachment;
}
Functions
Name![]() |
Description |
---|---|
commerce_billy_mail_attachment_mail_alter | Implements hook_mail_alter(). |
commerce_billy_mail_attachment_menu | Implements hook_menu(). |
_commerce_billy_mail_attachment_get_attachment | Returns the mail attachment(s). |