I have a content type that is used for temporary access. The node is created and has an expiration date; it's deleted after that date. On this node there is a user reference field; only the users added to this field should have access to viewing this node. I can't find a hook to handle this access. In Drupal 7 I used hook_node_access(), but it doesn't seem to exist for Drupal 9.

The only information I'm looking for is how to tap into the access privileges for a given node type. After that I can handle the logic of what users are contained in the reference field.

1 Answer 1


Drupal 9 still uses hook_node_access(). It's documented under hook_ENTITY_TYPE_access() because it's invoked for every existing entity, not just for the Node entity.
If mymodule is the module that implements that hook for the Node entity, the function implementing the hook would be mymodule_node_access(), exactly as in Drupal 7. The Drupal 7 code still needs to be ported to Drupal 9, as many details changed between Drupal 7 and Drupal 9.

If then you need to check the access for different entities, you could implement hook_entity_access().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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