O'Reilly logo

Drupal 7 Module Development by Ken Rickard, John Wilkins, Larry Garfield, Matt Butcher, Greg Dunlap, Matt Farina

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating the role access module

We begin with the standard module .info file and a stub .module file, as shown below:

; $Id$
name = Role Access
description = Limit content access by user role.
core = 7.x
files[] = role_access.module

Save this as role_access.info inside a /sites/default/modules/role_access/ directory.

Then create a stub role_access.module file:

<?php
// $Id$
/**
* @file
* Role access module file.
*
* Provides a simple content access scheme based on the
* author's role.
*/

Now we are ready to begin building our module. The code in the next sections will all add to this base file.

Using hook_node_access_records()

Enforcing rules with a node access module takes two parts. The first is writing your module's rules to the {node_access} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required