1

I have a taxonomy vocabulary that I use in many different content types. I want to restrict, programmatically, access rights to specific content types. As in, a specific role is not able to view particular content types unless they directly authored the item. This includes any view of a particular node (full, teaser, etc.). I've implemented hook_node_access as follows:

function progress_reporting_node_access($node, $op, $account) {
  if ($account->uid == 0) {
    return NODE_ACCESS_IGNORE;
  }
  if (_is_tagged($node,$account) && $op == 'update') {
    return NODE_ACCESS_ALLOW;
  }

  $records = _non_viewable_records();
  if (is_object($node) && in_array($node->type,$records)) {
    if ($op == 'view' && $node->uid != $account->uid) {
      drupal_set_message('Sorry, you cannot access this page. <a href="/">Click here to get back home</a>.','error');
      return NODE_ACCESS_DENY;
    }
  }

  return NODE_ACCESS_IGNORE;
}

The only thing that I didn't realize is that this affects a user only when they try to view the full node. So, when a user navigates to a taxonomy term's aggregation page, all the teasers of all the content that the term is referenced in shows up, regardless of the logic I applied in hook_node_access.

I need to somehow apply the same restrictions to all node views. In other words, when they navigate to the taxonomy term aggregation page, they don't see teasers that they're not supposed to see.

How can this be done, programmatically, exactly?

1

You're looking for hook_node_access_records:

http://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_access_records/7

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.