| 5 node_access_example.module | node_access_example_node_grants($account, $op) |
| 6 node_access_example.module | node_access_example_node_grants($account, $op) |
| 7 node_access_example.module | node_access_example_node_grants($account, $op) |
| 8 node_access_example.module | node_access_example_node_grants($account, $op) |
Implementation of hook_node_grants().
Tell the node access system what GIDs the user belongs to for each realm. In this example, we are providing two realms: the example realm, which has just one group id (1) and the user is either a member or not depending upon the operation and the access permission set.
We are also setting up a realm for the node author, though, to give it special privileges. That has 1 GID for every UID, and each user is automatically a member of the group where GID == UID.
File
- developer/
examples/ node_access_example.module, line 72 - This is an example illustrating how to restrict access to nodes based on some criterion associated with the user.
Code
function node_access_example_node_grants($account, $op) {
if ($op == 'view' && user_access('access private content', $account)) {
$grants['example'] = array(1);
}
if (($op == 'update' || $op == 'delete') && user_access('edit private content', $account)) {
$grants['example'] = array(1);
}
$grants['example_author'] = array($account->uid);
return $grants;
}
Login or register to post comments