-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.module
123 lines (105 loc) · 3.34 KB
/
log.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/**
* @file
* Hooks and customizations for the log module.
*/
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\log\Entity\LogInterface;
use Drupal\log\Event\LogEvent;
/**
* Implements hook_help().
*/
function log_help($route_name, RouteMatchInterface $route_match) {
$output = '';
// Main module help for the log module.
if ($route_name == 'help.page.log') {
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Provides Log entity') . '</p>';
}
return $output;
}
/**
* Implements hook_ENTITY_TYPE_presave().
*/
function log_log_presave(LogInterface $log) {
// Dispatch an event on log presave.
// @todo Replace this with core event via https://www.drupal.org/node/2551893.
$event = new LogEvent($log);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch($event, LogEvent::PRESAVE);
}
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function log_log_insert(LogInterface $log) {
// Dispatch an event on log insert.
// @todo Replace this with core event via https://www.drupal.org/node/2551893.
$event = new LogEvent($log);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch($event, LogEvent::INSERT);
}
/**
* Implements hook_ENTITY_TYPE_update().
*/
function log_log_update(LogInterface $log) {
// Dispatch an event on log update.
// @todo Replace this with core event via https://www.drupal.org/node/2551893.
$event = new LogEvent($log);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch($event, LogEvent::UPDATE);
}
/**
* Implements hook_ENTITY_TYPE_delete().
*/
function log_log_delete(LogInterface $log) {
// Dispatch an event on log delete.
// @todo Replace this with core event via https://www.drupal.org/node/2551893.
$event = new LogEvent($log);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch($event, LogEvent::DELETE);
}
/**
* Implements hook_theme().
*/
function log_theme() {
return [
'log' => [
'render element' => 'elements',
],
];
}
/**
* Implements hook_theme_suggestions_HOOK().
*/
function log_theme_suggestions_log(array $variables) {
$suggestions = [];
$log = $variables['elements']['#log'];
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
$suggestions[] = 'log__' . $sanitized_view_mode;
$suggestions[] = 'log__' . $log->bundle();
$suggestions[] = 'log__' . $log->bundle() . '__' . $sanitized_view_mode;
$suggestions[] = 'log__' . $log->id();
$suggestions[] = 'log__' . $log->id() . '__' . $sanitized_view_mode;
return $suggestions;
}
/**
* Prepares variables for log templates.
*
* Default template: log.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the log information and any
* fields attached to the log. Properties used:
* - #log: A \Drupal\log\Entity\Log object. The log entity.
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_log(&$variables) {
$variables['log'] = $variables['elements']['#log'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}