-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_template.module
executable file
·96 lines (80 loc) · 2.73 KB
/
module_template.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
95
96
<?php
/**
* @file
* module_template.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Render\Markup;
use Drupal\module_template\lib\general\MarkdownParser;
/**
* Implements hook_help().
*/
function module_template_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.module_template':
/* Añado el contenido del archivo README.md a la ayuda del módulo */
$parser = new MarkdownParser();
$module_path = \Drupal::service('extension.path.resolver')
->getPath('module', "module_template");
$readme_ruta = $module_path . "/README.md";
$contenido = '';
if (file_exists($readme_ruta)) {
$contenido = file_get_contents($readme_ruta);
$contenido = Markup::create($parser->text($contenido));
if ($contenido) {
$template_path = $module_path . "/templates/custom/help.html.twig";
$template = file_get_contents($template_path);
$build = [
'description' => [
'#type' => 'inline_template',
'#template' => $template,
'#context' => [
'readme' => $contenido,
],
],
];
return $build;
}
}
default:
}
}
/**
* 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'],
];
}
}
}