-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalet.module
79 lines (70 loc) · 1.46 KB
/
valet.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
<?php
/**
* @file
* Contains valet.module.
*/
use Drupal\Core\Cache\Cache;
use Drupal\user\RoleInterface;
/**
* Implements hook_page_bottom().
*
* Add valet markup to the bottom of the page automatically.
*/
function valet_page_bottom(array &$page_bottom) {
if (\Drupal::currentUser()->hasPermission('access valet')) {
$page_bottom['valet'] = [
'#type' => 'valet',
'#cache' => [
'keys' => ['valet'],
'contexts' => ['user.permissions'],
'tags' => ['valet'],
],
];
}
}
/**
* Implements hook_theme().
*/
function valet_theme() {
return [
'valet' => [
'render element' => 'element',
],
];
}
/**
* Implements hook_ENTITY_TYPE_presave().
*/
function valet_user_role_presave(RoleInterface $role) {
valet_cache_flush();
}
/**
* Implements hook_modules_installed().
*/
function valet_modules_installed($modules, $is_syncing) {
valet_cache_flush();
}
/**
* Implements hook_modules_uninstalled().
*/
function valet_modules_uninstalled($modules, $is_syncing) {
valet_cache_flush();
}
/**
* Implements hook_cache_flush().
*/
function valet_cache_flush() {
Cache::invalidateTags(['valet', 'valet_resources']);
// Reset cache.
valet_reset_cache_id();
}
/**
* Reset the cache id.
*/
function valet_reset_cache_id() {
$set = &drupal_static(__FUNCTION__, FALSE);
if (!$set) {
$set = TRUE;
Drupal::state()->set('valet.cache_id', base_convert(\Drupal::time()->getRequestTime(), 10, 36));
}
}