forked from torrance/domain_og_bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain_og.module
100 lines (93 loc) · 3.07 KB
/
domain_og.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
<?php
/**
* Bridge module to allow Domain Access and Organic Groups permissions
* to coexist by creating a different node_access "realm" that merges the
* node_access rules of both modules
*
* From http://drupal.org/node/1355272
*
* Thanks for the help and input to agentrickard and BrightBold
*/
/**
* Implements hook_node_access_records_alter().
*
* Creates a different node_access "realm" (domain_og) by merging the
* node_access settings of the Domain Access and the Organic Group modules.
*/
function domain_og_node_access_records_alter(&$grants, $node) {
$domain_ids = array();
$og_grants = array();
foreach ($grants as $key => $grant) {
switch ($grant['realm']) {
case 'domain_id':
$domain_ids[] = $grant['gid'];
break;
// We treat domain_site as just another domain with id = 'all'.
case 'domain_site':
$domain_ids[] = 'all';
break;
case 'group_access_authenticated': // OG 1.x
case 'og_access:node': // OG 2.x
$og_grants[] = $grant;
break;
}
}
// If there are access records for both domain and og, then we create our own
// combined record.
foreach ($domain_ids as $domain_id) {
foreach ($og_grants as $og_grant) {
$grants[] = array(
'realm' => "domain_og_{$domain_id}",
'gid' => $og_grant['gid'],
'grant_view' => $og_grant['grant_view'],
'grant_update' => $og_grant['grant_update'],
'grant_delete' => $og_grant['grant_delete'],
'priority' => 0,
);
}
}
// If both domain grants and og grants exist for this node, then we are now
// managing access to this node. Delete their grants from entering the record.
if (!empty($domain_ids) && !empty($og_grants)) {
foreach ($grants as $key => $grant) {
switch ($grant['realm']) {
case 'domain_id':
case 'domain_site':
case 'group_access_authenticated': // OG 1.x
case 'og_access:node': // OG 2.x
unset($grants[$key]);
}
}
}
}
/**
* Implements hook_node_grants_alter().
*
* Based on the new node_access "realm" (domain_og) it grants or revokes access
* to nodes while ignoring the original node_access settings in Domain Access
* and Organic Groups
*/
function domain_og_node_grants_alter(&$grants, $account, $op) {
$user_domains = array();
$user_groups = array();
// We treat domain_site as just another domain with id = 'all'.
if (isset($grants['domain_site'])) {
$user_domains = array_merge($user_domains, array('all'));
}
if (!empty($grants['domain_id'])) {
$user_domains = array_merge($user_domains, $grants['domain_id']);
}
// OG 1.x
if (!empty($grants['group_access_authenticated'])) {
$user_groups = array_merge($user_groups, $grants['group_access_authenticated']);
}
// OG 2.x
if (!empty($grants['og_access:node'])) {
$user_groups = array_merge($user_groups, $grants['og_access:node']);
}
foreach ($user_domains as $user_domain) {
foreach ($user_groups as $user_group) {
$grants["domain_og_{$user_domain}"][] = $user_group;
}
}
}