-
Notifications
You must be signed in to change notification settings - Fork 0
/
onovas_add_calendar_block.module
executable file
·86 lines (75 loc) · 2.3 KB
/
onovas_add_calendar_block.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
<?php
/**
* @file
* onovas_add_calendar_block.module.
*/
use Drupal\Core\Render\Markup;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\onovas_add_calendar_block\lib\general\MarkdownParser;
/**
* Implements hook_help().
*/
function onovas_add_calendar_block_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.onovas_add_calendar_block':
/* 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', "onovas_add_calendar_block");
$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_modules_installed().
*/
function onovas_add_calendar_block_modules_installed($modules) {
if (in_array('onovas_add_calendar_block', $modules)) {
// Be friendly to your users: what to do after install?
$url = Url::fromRoute('onovas_add_calendar_block.settings');
if (PHP_SAPI != 'cli') {
\Drupal::messenger()->addMessage(t('You can now <a href="@url_settings">configure the onovas: Add Calendar Block module</a> for your site.',
['@url_settings' => $url->toString()]), 'status');
}
}
}
/**
* Implements hook_theme().
*/
function onovas_add_calendar_block_theme($existing, $type, $theme, $path) {
return [
'onovas_add_calendar_block' => [
'variables' => [
'node' => NULL,
'items' => [],
'show_counter' => FALSE,
'older' => FALSE,
],
],
'onovas_add_calendar_counter' => [
'variables' => [
'older' => FALSE,
],
],
];
}