Hi all,
I'm trying to write a module to grant access to public or private nodes to users, based on their roles.
I'm starting with node_access_example.module in drupal-contributions, but it is not working as expected.
I'm trying to undestand the logic, but I did not undestand what the hook_node_grants() should return.
these are the infor I found on drupaldocs.org:
All node access modules are queried using hook_node_grants() to assemble a list of "grant IDs" for the user. This list is compared against the table. If any row contains the node ID in question (or 0, which stands for "all nodes"), one of the grant IDs returned, and a value of TRUE for the operation in question, then access is granted. Note that this table is a list of grants; any matching row is sufficient to grant access to the node.
So, what should I return as grant IDs ?? Could you help me in understanding what to specify in hook_node_grants ?
Actually, in the module, the code is, but I can't undestand the logic of $grants array():
[?php
function node_access_security_node_grants($account, $op) {
$grants = array();
//print user_access('access private content', $account); exit;
if (user_access('access private content', $account)) {
$grants[] = 1;
}
else if (user_access('access content', $account)) {
$grants[] = 0;
}
//print_r($account->roles); exit;
return array('security' => $grants);