Jump to content

Add functions (pre/post/...) to an existing node

From NusaATK
Revision as of 06:41, 20 August 2009 by Woody (talk | contribs)

ATK Howto: Add functions (pre/post/...) to an existing node

Complexity: Advanced
Author: Thomas Holz <vhskids@gmx.de>

List of other Howto's

Modifiers allow you to modify nodes on before they are used. To add functions like preUpdate use atkTriggerListener


Example of using atkTriggerListener:

Add the following code in your module_preload.inc (if this file is not present, create it in your module's directory):

 $modifiers[] = 'modules.node';

In your module.inc:

 class mod_mymodule extends atkModule 
 {
    function module_node_modifier(&$node)
    {
        atkimport("module.mymodule.myListener");
        $node->addListener(new MyListener());
    }
 }

now setup class.myListener.inc. The Listner contain the new functions. They will be called automatically by the node.

  atkimport("atk.utils.atktriggerlistener");

  class MyListener extends atkTriggerListener
  {
  
  function preUpdate( &$record )
  { 
    do some code....
    return true;
  }