Dojo Lesson #8 -- db_rewrite_sql() and the node_access system

You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

UPDATE: Andy Kirkham (ajk^ in IRC) has volunteered to do this lesson this Sunday! Cheers! --joshk

This lesson will provide an introduction to db_rewrite_sql() and Drupal's node access system. What is db_rewrite_sql() and why should I care? Initially, we'll create a basic module that uses hook_db_rewrite_sql() to implement a basic node access system that demonstrates what happens internally.

Once the concepts are grasped we'll lift the hood on some Drupal access control contrib modules and see how these work using Drupal's node grant system.

Basic Node Access Control

  • Create a basic module that restricts access to anonymous users but allows access for authenticated users on certain nodes.
  • Our personal access table and pre-populating it (for demonstration purposes).
  • hook_form_alter() to add a checkbox to the node edit form.
  • hook_nodeapi() to create a flag on the node and apply viewing access control.
  • hook_db_rewrite_sql() to implement the list view access control.

Basic Taxonomy Access Control

  • Using hook_db_rewrite_sql() to implement the list view access control by taxonomy.
  • Working around Drupal Core's update limitation.

Drupal 5's node_access system


¡Maravilloso! Just what the

victorkane's picture


Just what the doctor ordered!

Hope it happens this Sunday.

Will ACL be on the horizon somewhere?

Victor Kane

Yeah, this is a great topic --

bonobo's picture

and I second Victor's question: will the ACL module be in the house? I'd love to see some discussion of user controlled node level access control that respects OG access controls.

Andy -- take it away!




lapur's picture

It's great to learn the node access system. thank you!
It'd be helpful if the teacher can point out any significant differences between 4.7 and 5.0 for people who are on 4.7.


Tresler's picture

This is something that I've been wanting for a while. We should probably test out the skypecast et. al. today or tomorrow to avoid last Sunday's problems. Ping me if you coul duse a hand with that. I'll tr to be in the dojo channel when I can.

Tresler Designs

Might be worth looking at this

I think that link is in the site

Senpai's picture


I'm pretty sure we added that link to the lesson at

Joel Farris | my 'certified to rock' score

Finally finished the wiki class notes!

victorkane's picture

Andy, I have finally finished the wiki class notes (it was an excellent class and you really deserved to have the notes put up at last):

Lesson #8 Class Notes wiki -- db_rewrite_sql() and the Drupal 5's node_access system

Please take a look for quality control purposes. Everything is done except for the last 5-10 minutes, please feel free to edit the wiki.

Victor Kane

Excellent Job!

simplymenotu's picture

I browsed through the wiki, wonderful job. :-)

Question: Wouldn't it be helpful to provide the link to the Screencast?


I put that in...

victorkane's picture

I went ahead and put that in (of course, it is posted on the site, where, as a torrent file which may tend to be time dated, any update might make more sense), it is a great screencast.

Victor Kane

Drupal Dojo

Group organizers

Group events

Add to calendar

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: