In hook_node_grants() I want to check if user ID is equal to a node's field value, But there is only two arguments: $account and $op

How can I access the node object that is being checked for grants?


A better approach to this would be to implement hook_node_api that checks the current $user's permissions to the loaded field then does something.

function custom_module_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  //get the current user
  global $user;

  switch ($op) {
    case 'load':
      //do some logic with $node and with the current $user's roles

    //(optional)add other cases for other operations


alternatively you can try template_preprocess_node

function theme_name_preprocess_node(&$variables) {
  global $user;
  $node = $variables['node'];

  //do some stuff with $node and $user
  • 1
    Unfortunately these don't allow to prevent a node from listing and denying access to node before loading – hpn Oct 27 '11 at 14:39
  • This doesn't solve the problem. It won't control access to the node. – codeinthehole Jan 23 '15 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.