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

From Achievo/ATK Wiki

Jump to: navigation, search

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 
 {
    public 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
  {
      public function preUpdate( &$record )
      { 
          do some code....
          return true;
      }
  }
Personal tools
Navigation