18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9<br />

The key to Devel Node Access is its own internal hook system, which allows node<br />

access modules to declare a readable summary of their rules. Writing this hook is<br />

good practice, since it helps you articulate what your module does.<br />

Using hook_node_access_explain()<br />

hook_node_access_explain() is a function that should be responded to only by the<br />

module that sets the grants returned by hook_node_access_records(). So for our<br />

sample, we will implement it in the base Role Access module.<br />

The hook passes one argument $row, which is an object representing one row from<br />

the {node_access} table. Your module should inspect the data, and respond with<br />

information if the $row belongs to it.<br />

/**<br />

* Implement hook_node_access_explain().<br />

*/<br />

function role_access_node_access_explain($row) {<br />

// If not our grant, ignore.<br />

if ($row->realm != 'role_access') {<br />

return NULL;<br />

}<br />

[ 283 ]

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

Saved successfully!

Ooh no, something went wrong!