-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_restricted_access.module
More file actions
58 lines (52 loc) · 1.4 KB
/
node_restricted_access.module
File metadata and controls
58 lines (52 loc) · 1.4 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
<?php
/**
* @file
* Contains node_restricted_access.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\NodeInterface;
/**
* Implements hook_help().
*/
function node_restricted_access_help($route_name, RouteMatchInterface $arg) {
switch ($route_name) {
// Main module help for the node_restricted_access module.
case 'help.page.node_restricted_access':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Provides the ability to restrict node access based on permission') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_node_access_records().
*/
function node_restricted_access_node_access_records(NodeInterface $node) {
$grants = [];
if ($node->hasField('field_restricted_access') && $node->field_restricted_access->value == 1) {
$grants[] = array(
'realm' => 'node_restricted_access',
'gid' => 0,
'grant_view' => 1,
'grant_update' => 0,
'grant_delete' => 0,
'langcode' => 'en',
);
}
return $grants;
}
/**
* Implements hook_node_grants().
*/
function node_restricted_access_node_grants(AccountInterface $account, $op) {
$grants = [];
if ($op == 'view') {
if ($account->hasPermission('view restricted content')) {
$grants['node_restricted_access'][] = 0;
return $grants;
}
}
return $grants;
}