| 5 core.php | hook_node_access_records($node) |
| 6 core.php | hook_node_access_records($node) |
| 7 node.api.php | hook_node_access_records($node) |
| 8 node.api.php | hook_node_access_records($node) |
Set permissions for a node to be written to the database.
When a node is saved, a module implementing hook_node_access_records() will be asked if it is interested in the access permissions for a node. If it is interested, it must respond with an array of permissions arrays for that node.
Each permissions item in the array is an array with the following elements:
- 'realm': The name of a realm that the module has defined in hook_node_grants().
- 'gid': A 'grant ID' from hook_node_grants().
- 'grant_view': If set to TRUE a user that has been identified as a member of this gid within this realm can view this node.
- 'grant_update': If set to TRUE a user that has been identified as a member of this gid within this realm can edit this node.
- 'grant_delete': If set to TRUE a user that has been identified as a member of this gid within this realm can delete this node.
- 'priority': If multiple modules seek to set permissions on a node, the realms that have the highest priority will win out, and realms with a lower priority will not be written. If there is any doubt, it is best to leave this 0.
Related topics
File
- developer/
hooks/ core.php, line 1529 - These are the hooks that are invoked by the Drupal core.
Code
<?php
function hook_node_access_records($node) {
if (node_access_example_disabling()) {
return;
}
// We only care about the node if it's been marked private. If not, it is
// treated just like any other node and we completely ignore it.
if ($node->private) {
$grants = array();
$grants[] = array(
'realm' => 'example',
'gid' => 1,
'grant_view' => TRUE,
'grant_update' => FALSE,
'grant_delete' => FALSE,
'priority' => 0,
);
// For the example_author array, the GID is equivalent to a UID, which
// means there are many many groups of just 1 user.
$grants[] = array(
'realm' => 'example_author',
'gid' => $node->uid,
'grant_view' => TRUE,
'grant_update' => TRUE,
'grant_delete' => TRUE,
'priority' => 0,
);
return $grants;
}
}
?> Login or register to post comments
Comments
reason to replace hook_access
http://drupal.org/node/537862
permissions rebuild
Note that any changes to a module you're working on that implements this will probably require the permissions to be rebuilt.
You can flag this need from your module with
http://api.drupal.org/api/drupal/modules--node--node.module/function/nod...
You can rebuild permissions in your site on the /admin/content/node-settings page