Score:0

Node access based on the user reference field

mx flag

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.

Score:0
us flag

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().

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.