forked from webflo/drupal-swiftmailer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
swiftmailer.module
94 lines (79 loc) · 2.89 KB
/
swiftmailer.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* @file
* This is the primary module file.
*/
include_once __DIR__ . '/includes/helpers/utilities.inc';
// Define permissions.
define('SWIFTMAILER_ADMINISTER', 'swiftmailer_administer');
// Define message formats.
define('SWIFTMAILER_FORMAT_PLAIN', 'text/plain');
define('SWIFTMAILER_FORMAT_HTML', 'text/html');
// Define transport types.
define('SWIFTMAILER_TRANSPORT_SMTP', 'smtp');
define('SWIFTMAILER_TRANSPORT_SENDMAIL', 'sendmail');
define('SWIFTMAILER_TRANSPORT_NATIVE', 'native');
define('SWIFTMAILER_TRANSPORT_SPOOL', 'spool');
// Define header types.
define('SWIFTMAILER_HEADER_TEXT', 'text');
define('SWIFTMAILER_HEADER_PARAMETERIZED', 'parameterized');
define('SWIFTMAILER_HEADER_MAILBOX', 'mailbox');
define('SWIFTMAILER_HEADER_DATE', 'date');
define('SWIFTMAILER_HEADER_ID', 'ID');
define('SWIFTMAILER_HEADER_PATH', 'path');
// Define system variables defaults.
define('SWIFTMAILER_VARIABLE_RESPECT_FORMAT_DEFAULT', FALSE);
define('SWIFTMAILER_VARIABLE_CONVERT_MODE_DEFAULT', FALSE);
define('SWIFTMAILER_VARIABLE_PATH_DEFAULT', '');
define('SWIFTMAILER_VARIABLE_FORMAT_DEFAULT', 'text/plain');
define('SWIFTMAILER_VARIABLE_CHARACTER_SET_DEFAULT', 'UTF-8');
/**
* Implements hook_mail().
*/
function swiftmailer_mail($key, &$message) {
$user = \Drupal::currentUser();
//$message['params']['format'] = SWIFTMAILER_FORMAT_HTML;
$text[] = '<h3>' . t('Dear !user,', array('!user' => $user->getUsername())) . '</h3>';
$text[] = '<p>' . t('This e-mail has been sent from !site by the Swift Mailer module. The module has been successfully configured.', array('!site' => variable_get('site_name', 'a Drupal site'))) . '</p>';
$text[] = t('Kind regards') . '<br /><br />';
$text[] = t('The Swift Mailer module');
$message['subject'] = t('Swift Mailer has been successfully configured!');
$message['body'] = $text;
}
/**
* Implements hook_theme().
*/
function swiftmailer_theme($existing, $type, $theme, $path) {
return array(
'swiftmailer' => array(
'variables' => array(
'message' => array(),
),
'mail theme' => TRUE,
),
);
}
/**
* Implements hook_theme_suggestions_HOOK() for swiftmailer.
*/
function swiftmailer_theme_suggestions_swiftmailer(array $variables) {
$suggestions = [];
$suggestions[] = 'swiftmailer';
$suggestions[] = 'swiftmailer__' . $variables['message']['module'];
$suggestions[] = 'swiftmailer__' . $variables['message']['module'] . '__' . $variables['message']['key'];
return $suggestions;
}
/**
* Prepares variables for swiftmailer templates.
*
* Default template: swiftmailer.html.twig.
*
* @param array $variables
* An associative array containing:
* - message: An associative array containing the message array.
* - body: The processed body.
*/
function template_preprocess_swiftmailer(&$variables) {
$variables['subject'] = $variables['message']['subject'];
$variables['body'] = $variables['message']['body'];
}