1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Dummy module implementing node related hooks to test API interaction with
|
6 |
|
|
* the Node module.
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Implements hook_node_grants().
|
11 |
|
|
*/
|
12 |
|
|
function acl_node_test_node_grants($account, $op) {
|
13 |
|
|
// Give everyone full grants so we don't break other node tests.
|
14 |
|
|
// Our node access tests asserts three realms of access.
|
15 |
|
|
// See testGrantAlter().
|
16 |
|
|
return array(
|
17 |
|
|
'test_article_realm' => array(1),
|
18 |
|
|
'test_page_realm' => array(1),
|
19 |
|
|
'test_alter_realm' => array(2),
|
20 |
|
|
);
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
/**
|
24 |
|
|
* Implements hook_node_access_records().
|
25 |
|
|
*
|
26 |
|
|
* Implicit View by All is allowed.
|
27 |
|
|
*/
|
28 |
|
|
function acl_node_test_node_access_records($node) {
|
29 |
|
|
$grants = array();
|
30 |
|
|
if ($node->type == 'article') {
|
31 |
|
|
// Create grant in arbitrary article_realm for article nodes.
|
32 |
|
|
$grants[] = array(
|
33 |
|
|
'realm' => 'test_article_realm',
|
34 |
|
|
'gid' => 1,
|
35 |
|
|
'grant_view' => 1,
|
36 |
|
|
'grant_update' => 0,
|
37 |
|
|
'grant_delete' => 0,
|
38 |
|
|
'priority' => 0,
|
39 |
|
|
);
|
40 |
|
|
}
|
41 |
|
|
elseif ($node->type == 'page') {
|
42 |
|
|
// Create grant in arbitrary page_realm for page nodes.
|
43 |
|
|
$grants[] = array(
|
44 |
|
|
'realm' => 'test_page_realm',
|
45 |
|
|
'gid' => 1,
|
46 |
|
|
'grant_view' => 1,
|
47 |
|
|
'grant_update' => 0,
|
48 |
|
|
'grant_delete' => 0,
|
49 |
|
|
'priority' => 0,
|
50 |
|
|
);
|
51 |
|
|
}
|
52 |
|
|
return $grants;
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
/**
|
56 |
|
|
* Implements hook_node_access_records_alter().
|
57 |
|
|
*/
|
58 |
|
|
function acl_node_test_node_access_records_alter(&$grants, $node) {
|
59 |
|
|
if (!empty($grants)) {
|
60 |
|
|
foreach ($grants as $key => $grant) {
|
61 |
|
|
// Alter grant from test_page_realm to test_alter_realm and modify the gid.
|
62 |
|
|
if ($grant['realm'] == 'test_page_realm' && $node->promote) {
|
63 |
|
|
$grants[$key]['realm'] = 'test_alter_realm';
|
64 |
|
|
$grants[$key]['gid'] = 2;
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
/**
|
71 |
|
|
* Implements hook_node_grants_alter().
|
72 |
|
|
*
|
73 |
|
|
* Returns an empty array of grants to prove that we can alter by reference.
|
74 |
|
|
*/
|
75 |
|
|
function acl_node_test_node_grants_alter(&$grants, $account, $op) {
|
76 |
|
|
$grants = array();
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Implements hook_node_presave().
|
81 |
|
|
*/
|
82 |
|
|
function acl_node_test_node_presave($node) {
|
83 |
|
|
if ($node->title == 'testing_node_presave') {
|
84 |
|
|
// Sun, 19 Nov 1978 05:00:00 GMT
|
85 |
|
|
$node->created = 280299600;
|
86 |
|
|
// Drupal 1.0 release.
|
87 |
|
|
$node->changed = 979534800;
|
88 |
|
|
}
|
89 |
|
|
} |