Example: Node Access

Same name in other branches
  1. 7.x-1.x node_access_example/node_access_example.module \node_access_example

Examples of node access restriction. (drupal 6)

This is an example illustrating how to restrict access to nodes based on some criterion associated with the user.

This example module will simply set a single flag on a node: 'private'. If the flag is set, only users with the 'view private content' flag can see the node, and all users with 'edit private content' can edit (but not delete) the node.

Additionally we will ensure that the node author can always view, edit, and delete the node by providing an additional access realm that grants privileges to the node's author.

Database definition:


  CREATE TABLE node_access_example (
    nid int(10) unsigned NOT NULL default '0' PRIMARY KEY,
    private int,
    KEY `node_example_nid` (nid)
  )

This example is part of the Examples for Developers Project which you can download and experiment with here: http://drupal.org/project/examples

Parent topics

File

node_access_example/node_access_example.module, line 28

Functions

Title Sort descending File name Summary
node_access_example_form_alter node_access_example/node_access_example.module Implementation of hook_form_alter()
node_access_example_nodeapi node_access_example/node_access_example.module Implementation of hook_nodeapi().
node_access_example_node_access_records node_access_example/node_access_example.module Implements hook_node_access_records().
node_access_example_node_grants node_access_example/node_access_example.module Implements hook_node_grants().
node_access_example_perm node_access_example/node_access_example.module Implementation of hook_perm().

Constants

Title Sort descending File name Summary
NODE_ACCESS_EXAMPLE_GRANT_ALL node_access_example/node_access_example.module Here we define a constant for our node access grant ID, for the example realm.
This ID could be any integer, but here we choose 23,
because it is this author's favorite number.