I have inherited a complex site with multiple node type.

My current task is to prevent some nodes from loading based on some preset conditions. To accomplish that I used hook_node_view in the following function:

function accessibility_node_view($node, $view_mode, $langcode){
    drupal_set_message('Node View Responding'); 

That's just a simple test but I find that code responds on some nodes types but not on others.

Does anyone know a reason why that would be happening, please?

  • 1
    where does this function live? your theme template.php, custom module? Aug 9, 2016 at 15:38
  • @longboardnode: The function is in a custom module
    – sisko
    Aug 9, 2016 at 20:43
  • Are you sure the content type you try to hide are nodes ? Because hook_node_view fire before all node rendering.
    – TytooF
    Aug 9, 2016 at 21:24
  • @TytooF: Absolutely 100% sure they are nodes. They list in the content section and have the same page tabs as the nodes which respond to my code
    – sisko
    Aug 10, 2016 at 9:36
  • I implemented hook_init() in my module and the message I included in that function loads on all node. Of course, hook_node_view() is the most appropriate for my purposes but it doesn't respond :-(
    – sisko
    Aug 10, 2016 at 9:39

1 Answer 1


After a long and confusing time experimenting with a lot of various hooks, I finally found hook_node_access.

I'm not sure if I had tried it previously but it seems to do the trick.

I used the following code to test when any node of any type is being viewed at which point I test for the presence of an particular taxonomy and value to determine if I want certain roles to view and read the page:

function mymodule_node_access($node, $op, $account){
    if($op == 'view'){
        if( isset($node->field_accessibility['und'][0]) ){

I hope that helps @longboardnode


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.