Reputation: 15598
I am looking for a way to control access to a node (my own content type), even when it has the "published" bit set. I have a custom field (datetime) that specifies when the node should be available to visitors. How do I hook in to Drupal 7 to do that?
Best regards, Egil.
Upvotes: 1
Views: 787
Reputation: 61
I accomplished a similar thing using hook_node_access_records()
and hook_node_grants()
. My example is for a field within a node that restricts access on a group level, but the same concept works (more easily) for non-group content.
The description of what I did is here: https://drupal.stackexchange.com/questions/36269/how-to-restrict-node-access-to-nodes-based-on-field-value/83975#83975
However, it might be easier for you to follow Node Access Example Module: https://api.drupal.org/api/examples/node_access_example!node_access_example.module/7
That is exactly what I modified to get my code.
Upvotes: 2
Reputation: 2999
Have a look on node_access(), you should be able to do what you need there.
Upvotes: 2