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.

Node Access<br />

• The {node_access} table and its role<br />

• Defining your module's access rules<br />

• Using hook_node_access_records()<br />

• Using hook_node_grants()<br />

• Rebuilding the {node_access} table<br />

• Modifying the behavior of other modules<br />

• Using hook_node_access_records_alter()<br />

• Using hook_node_grants_alter()<br />

• Testing and debugging your module<br />

• Using Devel Node Access<br />

Node Access compared to user_access()<br />

and other permission checks<br />

Unlike user_access(), using the Node Access system is not a simple case of<br />

implementing a specific permission check before executing your code.<br />

As we saw in the last chapter, user_access() determines what code may be<br />

executed for a specific user under a given set of conditions. <strong>Drupal</strong>'s Node Access<br />

system is similar, but must account for variable conditions within a given set of<br />

nodes. For example, certain users may be allowed to edit any Basic page content<br />

but not allowed to edit any Article content. This condition means that <strong>Drupal</strong><br />

must be able to distinguish among different properties of each node.<br />

The Node Access API is a series of interrelated functions that provide a consistent<br />

programming interface for making these types of access checks. Due to the flexible<br />

nature of <strong>Drupal</strong> however, there are multiple ways to define and implement node<br />

access control mechanisms.<br />

How <strong>Drupal</strong> grants node permissions<br />

As we mentioned in the introduction, there are four fundamental operations that<br />

affect nodes: Create, View, Update and Delete. Collectively, these are referred to<br />

as CRUD (where View is replaced by Read). When dealing with nodes, it is vital<br />

to know which operation is being performed.<br />

[ 242 ]

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

Saved successfully!

Ooh no, something went wrong!