When to write a node access module

Clearly, hook_node_access() is a very powerful function. As we have seen, many common use-cases can be solved in just a few lines of code. So it is important for module developers to consider when to use hook_node_access() to implement access control as opposed to a complete node access module.

Since access control modules should not respond to the View operation, node access modules become necessary any time you need to use access rules to restrict access to the nodes that a user may view. The reason for this has to do with how Drupal builds its access controls when listing nodes. hook_node_access() is only effective for running access checks against individual nodes a fact made clear by the fact that the $node ...

Get Drupal 7 Module Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.