-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_template.module
More file actions
executable file
·62 lines (52 loc) · 1.77 KB
/
module_template.module
File metadata and controls
executable file
·62 lines (52 loc) · 1.77 KB
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
<?php
/**
* @file
* module_template.module.
*/
use Drupal\Core\Render\Markup;
/**
* Implements hook_toolbar_alter().
*/
function module_template_toolbar_alter(&$items) {
/* Añado iconos a la toolbar de administración */
$items['administration']['#attached']['library'][] = 'module_template/toolbar';
}
/**
* Implements hook_page_attachments().
*/
function module_template_page_attachments(array &$attachments) {
/* Añadir el CSS y JS a toda la web */
$attachments['#attached']['library'][] = 'module_template/global_libraries';
}
/**
* Implements hook_mail().
*/
function module_template_mail(string $key, array &$message, array $params) {
$config_site = \Drupal::config('system.site');
/* Cabeceras */
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
$message['from'] = $config_site->get('name') . '<' . $config_site->get('mail') . '>';
/* Copias del mensaje */
if (isset($params['Cc']) and !is_null($params['Cc'])) {
$message['headers']['Cc'] = $params['Cc'];
}
if (isset($params['Bcc']) and !is_null($params['Bcc'])) {
$message['headers']['Bcc'] = $params['Bcc'];
}
/* Datos comunes a todos los envíos */
$message['reply-to'] = $message['from'];
$message['subject'] = $params['subject'];
$message['body'][] = Markup::create($params['message']);
/* Compruebo si el mensaje tiene adjuntos */
if (isset($params['attachments'])) {
/* Solución para los adjuntos duplicados en Outlook. */
$message['params']['attachments'] = [];
foreach ($params['attachments'] as $attachment) {
$message['params']['attachments'][] = [
'filepath' => $attachment['filepath'],
'filename' => $attachment['filename'],
'filemime' => $attachment['filemime'],
];
}
}
}