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 contains six columns, each with a specific role in the API.<br />

• nid is an integer and is the foreign key to the {node} table, used as the JOIN<br />

field for SELECT statements.<br />

• gid is an integer and represents the grant id declared by a node access<br />

module. All gids are paired with an appropriate realm, as defined by<br />

the module.<br />

• realm is a string (maximum 255 characters) that indicates the name of the<br />

access rule assigned by a module. <strong>Module</strong>s may define multiple realms, and<br />

each realm may have multiple gids. Taken together, a realm/gid pair creates<br />

a specific access grant for the given node id.<br />

• grant_view is an integer that provides a Boolean value indicating that<br />

the grant in this row allows the node to be viewed by users with the<br />

proper permission.<br />

• grant_update is an integer that provides a Boolean value indicating that<br />

the grant in this row allows the node to be edited by users with the<br />

proper permission.<br />

• grant_delete is an integer that provides a Boolean value indicating that<br />

the grant in this row allows the node to be deleted by users with the<br />

proper permission.<br />

Taken together, each row of the {node_access} table defines a rule set for a node. A<br />

node may have more than one rule set. Note that the {node_access} table itself does<br />

not care about the publication status of the node. When defining your modules's<br />

realms, you should take into account how to handle access to unpublished content.<br />

Because they can write multiple records to the {node_access}<br />

table and add JOINs to most node queries, node access modules<br />

can be resource intensive. In order to keep performance high,<br />

sites that plan to use node access modules should generally allow<br />

for 5-10% additional processing power for the database server.<br />

Defining your module's access rules<br />

Now that we understand how <strong>Drupal</strong> limits access to nodes, we are ready to explore<br />

the API for module developers. Before we write any code, however, we should<br />

write out the access rules we wish to enforce and review them for accuracy and<br />

potential trouble.<br />

[ 264 ]

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

Saved successfully!

Ooh no, something went wrong!