forked from fsulib/embargoes
-
Notifications
You must be signed in to change notification settings - Fork 7
/
embargoes.module
122 lines (110 loc) · 3.32 KB
/
embargoes.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
<?php
/**
* @file
* Hook implementations.
*/
use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\NodeInterface;
/**
* Implements hook_ENTITY_TYPE_access().
*/
function embargoes_node_access(NodeInterface $node, $operation, AccountInterface $account) {
return \Drupal::service('embargoes.node_access')->isActivelyEmbargoed($node, $account);
}
/**
* Implements hook_ENTITY_TYPE_access().
*/
function embargoes_media_access(EntityInterface $media, $operation, AccountInterface $account) {
return \Drupal::service('embargoes.media_access')->isActivelyEmbargoed($media, $account);
}
/**
* Implements hook_ENTITY_TYPE_access().
*/
function embargoes_file_access(EntityInterface $file, $operation, AccountInterface $account) {
return \Drupal::service('embargoes.file_access')->isActivelyEmbargoed($file, $account);
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
function embargoes_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
\Drupal::service('embargoes.node_access')->setEmbargoMessage($node);
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
function embargoes_media_view(array &$build, EntityInterface $media, EntityViewDisplayInterface $display, $view_mode) {
\Drupal::service('embargoes.media_access')->setEmbargoMessage($media);
}
/**
* Implements hook_file_download().
*/
function embargoes_file_download($uri) {
$files = \Drupal::entityTypeManager()
->getStorage('file')
->loadByProperties(['uri' => $uri]);
$file = reset($files);
if ($file instanceof EntityInterface) {
$access = \Drupal::service('embargoes.file_access')->isActivelyEmbargoed($file, \Drupal::currentUser());
if ($access->isForbidden()) {
return -1;
}
}
}
/**
* Implements hook_theme().
*/
function embargoes_theme($existing, $type, $theme, $path) {
return [
'embargoes_ip_access_denied' => [
'template' => 'embargoes-ip-access-denied',
'variables' => [
'requested_resource' => NULL,
// Indexed array of ranges containing a 'proxy URL' (NULL if none exist)
// and a display 'label'.
'ranges' => [
[
'label' => NULL,
'proxy_url' => NULL,
],
],
'contact_email' => NULL,
],
],
'embargoes_policies' => [
'template' => 'embargoes-policies',
'variables' => [
'count' => NULL,
'embargo_info' => [],
],
],
'embargoes_notifications' => [
'template' => 'embargoes-notifications',
'variables' => [
'count' => NULL,
'embargo_info' => [],
'message' => NULL,
],
],
];
}
/**
* Implements hook_query_TAG_alter().
*/
function embargoes_query_node_access_alter(AlterableInterface $query) {
\Drupal::service('embargoes.query_tagger')->tagAccess($query, 'node');
}
/**
* Implements hook_query_TAG_alter().
*/
function embargoes_query_media_access_alter(AlterableInterface $query) {
\Drupal::service('embargoes.query_tagger')->tagAccess($query, 'media');
}
/**
* Implements hook_query_TAG_alter().
*/
function embargoes_query_file_access_alter(AlterableInterface $query) {
\Drupal::service('embargoes.query_tagger')->tagAccess($query, 'file');
}