#1045020 by Les Lim: Changed Remove obsolete nodereference and userreference module...
[project/devel.git] / devel_node_access.api.php
1 <?php
2
3 /**
4 * @file
5 * Hook provided by the Devel Node Access module.
6 */
7
8 /**
9 * @addtogroup hooks
10 * @{
11 */
12
13 /**
14 * Explain your records in the {node_access} table.
15 *
16 * In order to help developers and administrators understand the forces
17 * that control access to any given node, the DNA module provides the
18 * Devel Node Access block, which lists all the grant records in the
19 * {node_access} table for that node.
20 *
21 * However, every Node Access module is free in how it defines and uses the
22 * 'realm' and 'gid' fields in its records in the {node_access} table, and
23 * it's often difficult to interpret them. This hook passes each record
24 * that DNA wants to display, and the owning module is expected to return
25 * an explanation of that record.
26 *
27 * The explanation should not be localized (not be passed through t()), so
28 * that administrators seeking help can present English explanations.
29 *
30 * @param $row
31 * The record from the {node_access} table, as object. The member fields are:
32 * nid, gid, realm, grant_view, grant_update, grant_delete.
33 *
34 * @return
35 * A string with a (short!) explanation of the given {node_access} row,
36 * to be displayed in DNA's 'Devel Node Access' block. It will be displayed
37 * as HTML; any variable parts must already be sanitized.
38 *
39 * @see hook_node_access_records()
40 * @see devel_node_access_node_access_explain()
41 *
42 * @ingroup node_access
43 */
44 function hook_node_access_explain($row) {
45 if ($row->realm == 'mymodule_myrealm') {
46 if ($row->grant_view) {
47 $role = user_role_load($row->gid);
48 return 'Role ' . drupal_placeholder($role->name) . ' may view this node.';
49 }
50 else {
51 return 'No access.';
52 }
53 }
54 }
55
56 /**
57 * Acknowledge ownership of 'alien' grant records.
58 *
59 * Some node access modules store grant records directly into the {node_access}
60 * table rather than returning them through hook_node_access_records(). This
61 * practice is not recommended and DNA will flag all such records as 'alien'.
62 *
63 * If this is unavoidable, a module can confess to being the owner of these
64 * grant records, so that DNA can properly attribute them.
65 *
66 * @see hook_node_access_records()
67 *
68 * @ingroup node_access
69 */
70 function hook_node_access_acknowledge($grant) {
71 if ($grant['realm'] == 'mymodule_all' && $grant['nid'] == 0) {
72 return TRUE;
73 }
74 }
75
76 /**
77 * @} End of "addtogroup hooks".
78 */