Hi,

Hoping for some help.

I want to create a View based on nodes that returns two fields. I wish to display the following fields:

  • Content: Title
  • Global: PHP - Display 'a' if user has permission to access the node or 'b' if user does not have permission to access node

The PHP code I am using is:

<?php
if (drupal_valid_path($row->path)) {
  print 'a';
}
else {
  print 'b';
}
?>

The problem I am having is that by default, Views uses node access to only return nodes that the user has access to. This means that the list of nodes returned is only true where 'a'is true.

Now I can use 'Disable SQL rewriting' to turn this off, but it actually turns off node access which means the PHP will return 'a' for every node irrelevant of whether the use has permission to access or not.

My node access is based upon Roles.

Any advice or alternative ways to do this would be much appreciated.

Comments

D34dMan’s picture

Click on Advanced settings for the view, then in Query options, Disable SQL rewriting (which says "Disabling SQL rewriting will disable node_access checks as well as other modules that implement hook_query_alter().")