-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathldbase_embargoes.module
More file actions
99 lines (89 loc) · 2.86 KB
/
ldbase_embargoes.module
File metadata and controls
99 lines (89 loc) · 2.86 KB
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
<?php
/**
* @file
* Hook implementations.
*/
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\ldbase_embargoes\Access\EmbargoesFileAccessHandler;
use Drupal\node\NodeInterface;
/**
* Implements hook_ENTITY_TYPE_access().
*/
function ldbase_embargoes_node_access(NodeInterface $node, $operation, AccountInterface $account) {
return \Drupal::service('ldbase_embargoes.node_access')->isActivelyEmbargoed($node, $account);
}
/**
* Implements hook_ENTITY_TYPE_access().
*/
function ldbase_embargoes_media_access(EntityInterface $media, $operation, AccountInterface $account) {
return \Drupal::service('ldbase_embargoes.media_access')->isActivelyEmbargoed($media, $account);
}
/**
* Implements hook_ENTITY_TYPE_access().
*/
function ldbase_embargoes_file_access(EntityInterface $file, $operation, AccountInterface $account) {
return \Drupal::service('ldbase_embargoes.file_access')->isActivelyEmbargoed($file, $account);
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
function ldbase_embargoes_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
if (\Drupal::RouteMatch()->getRouteName() == 'entity.node.canonical') {
\Drupal::service('ldbase_embargoes.node_access')->setEmbargoMessage($node);
}
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
function ldbase_embargoes_media_view(array &$build, EntityInterface $media, EntityViewDisplayInterface $display, $view_mode) {
if (\Drupal::RouteMatch()->getRouteName() == 'entity.node.canonical') {
\Drupal::service('ldbase_embargoes.media_access')->setEmbargoMessage($media);
}
}
/**
* Implements hook_entity_type_alter().
*/
function ldbase_embargoes_entity_type_alter(array &$entity_types) {
if (isset($entity_types['file'])) {
$entity_types['file']->setHandlerClass('access', EmbargoesFileAccessHandler::class);
}
}
/**
* Implements hook_file_download().
*/
function ldbase_embargoes_file_download($uri) {
$files = \Drupal::entityTypeManager()
->getStorage('file')
->loadByProperties(['uri' => $uri]);
$file = reset($files);
if ($file instanceof EntityInterface) {
$access = \Drupal::service('ldbase_embargoes.file_access')->isActivelyEmbargoed($file, \Drupal::currentUser());
if ($access->isForbidden()) {
return -1;
}
}
}
/**
* Implements hook_theme().
*/
function ldbase_embargoes_theme($existing, $type, $theme, $path) {
return [
'ldbase_embargoes_policies' => [
'template' => 'ldbase-embargoes-policies',
'variables' => [
'count' => NULL,
'embargoes_info' => [],
],
],
'ldbase_embargoes_notifications' => [
'template' => 'ldbase-embargoes-notifications',
'variables' => [
'count' => NULL,
'embargoes_info' => [],
'message' => NULL,
],
],
];
}