-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd8_cache.module
65 lines (57 loc) · 1.55 KB
/
d8_cache.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
<?php
/**
* @file
* d8_cache.module
*/
// For hook_views_pre_views.
use Drupal\views\ViewExecutable;
// For hook_node_save.
use Drupal\Core\Cache\Cache;
use Drupal\node\NodeInterface;
/**
* Implements hook_node_presave().
*
* Invalid cache tags for node lists.
*/
function d8_cache_node_presave(NodeInterface $node) {
$cache_tag = 'node:type:' . $node->getType();
Cache::invalidateTags([$cache_tag]);
}
/**
* Implement hook_views_pre_view().
*
* Add the time in the header of our views.
*/
function d8_cache_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
$contenu = "Il est: " . date('H:i:s');
if ($view->id() == 'test_pages' && $display_id === 'page_1') {
$options = [
'id' => 'area_text_custom',
'table' => 'views',
'field' => 'area_text_custom',
'relationship' => 'none',
'group_type' => 'none',
'admin_label' => '',
'empty' => TRUE,
'tokenize' => FALSE,
'content' => $contenu,
'plugin_id' => 'text_custom',
];
$view->setHandler('page_1', 'header', 'area_text_custom', $options);
}
if ($view->id() == 'test_articles_block' && $display_id === 'block_1') {
$options = [
'id' => 'area_text_custom',
'table' => 'views',
'field' => 'area_text_custom',
'relationship' => 'none',
'group_type' => 'none',
'admin_label' => '',
'empty' => TRUE,
'tokenize' => FALSE,
'content' => $contenu,
'plugin_id' => 'text_custom',
];
$view->setHandler('block_1', 'header', 'area_text_custom', $options);
}
}