I have written a module that puts a "generate pdf" link on a node when it is viewed. What I now want to do is lock the original node after the pdf is generated.

I know I could just add a "locked" field to the content type I want to lock, and then programatically set that etc. But I'd prefer it to work with any content type.

How can I programatically disable the editing of a node? I'd prefer to install as few additional modules as possible.


For this you should have to implement hook_node_grants and hook_node_access_records. It look something like that -

  * Implement @hook_node_grants 
 function MODULENAME_node_grants($account, $op) {

  $grants =array();
 return $grants;

 * Implement @hook_node_access_records
function MODULENAME_node_access_records($node) {

  $grants = array();

  if ($node->type == 'node_type') { 
    $user_id = /* list of user id which you want to block */;

     // Revoke Permissions from these Users
    if (!empty($user_id) {
      foreach ($user_id as $uid) {
        if (isset($uid)) {

          $grants[] = array(
            'realm' => 'Node_Edit_Permission',
            'gid' => $uid,
            'grant_view' => 1,
            'grant_update' => 0,
            'grant_delete' => 0,
            'priority' => 0,

  return $grants;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.