18.10.2016 Views

Drupal 7 Module Development

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• Can this user bypass node access?<br />

Chapter 9<br />

New in <strong>Drupal</strong> 7, the bypass node access permission has been split from the<br />

administer nodes permission. This permission allows super-users to ignore<br />

all node access rules (including those enforced by hook_node_access()).<br />

Normally, this permission is only retained by user 1, but on some sites, select<br />

roles should always be allowed to view all nodes.<br />

• What node access permissions does this user have?<br />

Here, the function calls node_access_grants() to determine what node<br />

access permissions the user account has been granted. These grants are<br />

returned by your module's hook_node_grants() function. Each returned<br />

grant is used to create a new OR clause in the final node access query.<br />

Note that we said OR clause. This is crucial. Node access in<br />

<strong>Drupal</strong> is still a permissive system. If you are using multiple<br />

node access modules and one grants access, that access<br />

cannot be taken away by another node access module's<br />

grants. There are, however, ways to enforce "deny" grants<br />

through either hook_node_access() or hook_node_<br />

grants_alter(), which we will discuss later.<br />

• What action are we performing?<br />

The last question checks the operation being performed (View, Update, or<br />

Delete) in order to add the proper access clause against the grant_view,<br />

grant_update, or grant_delete columns of the {node_access} table.<br />

Unlike hook_node_access(), the query runs against the {node_access} table<br />

and does not care which individual node we are trying to view, update, or delete.<br />

Instead, the node access system here provides a layer of abstraction so that listing<br />

queries can be properly filtered according to the site's access rules.<br />

{node_access} table schema explained<br />

The {node_access} table works by storing the necessary information for running a<br />

proper JOIN to the {node} table based on the conditions described above. To fully<br />

understand how the above query example works (and to plan your node access<br />

module), let's examine the structure of the table itself.<br />

[ 263 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!