Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By dannybrowne on
Using drupal 7 I have implemented hook_node_access but am having real troulbe figuring out how to go a step further and achieve the following using hook_node_access_records and hook_node_grants:
For a given content type ('submission') I want to limit users with a particular role ('curator') to see only node that have a specific value set ('location')
An abridged version of my hook_node_access function is outlined below.
Any help greatly appreciated.
Danny.
function hook_node_access($node, $op, $account) {
// Get the currently logged in users role
$role = is_string($account) ? $account : $account->roles[4];
// Get the node type being rendered
$type = is_string($node) ? $node : $node->type;
if (($role == 'curator') && ($type == 'submission')){
$venue = 'london'
$location = 'london'
if (in_array($type, node_permissions_get_configured_types())) {
if (($op == 'view') && ($venue !== $location)) {
return NODE_ACCESS_DENY;
}
}
}
}