Community Documentation

Adding a trigger on node revision

Last updated February 26, 2011. Created by aufumy on July 13, 2010.
Edited by Fyrsten, benlotter. Log in to edit this page.

Scott Hadfield has an informative tutorial about triggers.

This is a short module, that works with triggers, triggerunlock module, to allow you to assign actions (e.g. send email) upon node revision.

<?php
/**
* Implementation of hook_hook_info().
*/
function my_custom_trigger_hook_info() {
  return array(
   
'my_custom_trigger' => array(
     
'nodeapi' => array(
       
'revision' => array(
         
'runs when' => t('After node revision is created'),
        ),
      ),
    ),
  );
}

/**
* Implementation of hook_nodeapi().
*/
function my_custom_trigger_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
 
// When creating a new revision
 
if ($op == 'update' && $node->revision == 1) {
   
$aids = _trigger_get_hook_aids('nodeapi', 'revision');
   
$context = array(
     
'hook' => 'nodeapi',
     
'op' => $op,
     
'node' => $node,
    );
   
actions_do(array_keys($aids), $node, $context);
  }
}
?>

Comments

About this page

Should this be placed under the module creation tutorial? It seems odd that it's here.

Re: About this page

I agree with vilepickle. This page seems out of place.

At the earliest

At the earliest, it could come after the introduction page describing actions: Writing actions.

And, to be honest, it looks to me like that page is a bit out of place, too.

This page shouldn't be here.

All of a sudden, it now discuss triggers without a proper introduction.

Page status

Needs updating

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Programmers

Develop for Drupal

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here