Jump to content

Using custom action handlers: Difference between revisions

From NusaATK
ReneB (talk | contribs)
Created page with '{{Howto|Easy|Rene Bakx <rene@nospamformeplease.71media.net>}} ==Using the atkActionHandler to extend a handler== Note upfront, this is only tested on ATK 6.5. Every action…'
 
No edit summary
Line 1: Line 1:
{{Howto|Easy|[[Rene Bakx]] <rene@nospamformeplease.71media.net>}}
{{Howto|Advanced|[[Rene Bakx]] <rene@nospamformeplease.71media.net>}}


==Using the atkActionHandler to extend a handler==
==Using the [[atkActionHandler]] to extend a handler==


Note upfront, this is only tested on ATK 6.5.
{{version|6.5}}


Every action, like export, add, delete etc, within a node can be extended to use your own action, or in the case of this snippet to change the behaviour of the export action.  
Every action, like export, add, delete etc, within a node can be extended to use your own action. In this case we use it to change the behaviour of the export action.  
The customer wanted to export every field of the node, regardless things that where on AF_HIDE_LIST without the need to toggle the buttons on every export.
 
Use case: you want the behaviour of the export action in ATK, but you want to tweak it slightly.


==Adding a handler to your node==
==Adding a handler to your node==
At the top of your node file, add the following lines:


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
atkimport("mymodule.myExporthandler");
// Import the class definition of myExportHandler
atkRegisterNodeHandler('myNode', 'export', new myExporthandler());
atkimport("mymodule.myExportHandler");
 
// Register the export handler class
atkRegisterNodeHandler('myNode', 'export', new myExportHandler());
</syntaxhighlight>
</syntaxhighlight>


Where the mymodule is ofcourse your module folder, the myExporthandler the name of your handler etc.
Where the mymodule is ofcourse your module folder, the myExportHandler the name of your handler.
The aktRegisterNodeHandler also takes a * as first parameter to match all the nodes in the scope, if you hook the node handler in your own extended atkNode for example.


The myExportHandler class is an extended atkActionHandler where some of the functions where overloaded, but the third parameter can also be a static method with two parameters (see atknode.Callhandler method)
The atkRegisterNodeHandler also takes a * as first parameter to match all the nodes in the scope, if you hook the node handler in your own extended atkNode for example.
 
The myExportHandler class is an extended [[atkActionHandler]] where some of the functions where overloaded, but the third parameter can also be a static method with two parameters (see atknode.Callhandler method).
 
A sample myExportHandler class could look like this:
 
<syntaxhighlight lang="php">
 
class myExportHandler extends atkExportHandler // extend the default exporting functionality
{
  public function ..... // override whichever function you want to change
}
</syntaxhighlight>


For a overview of default available and thus extendable actionHandler the handlers folder in your atk root.
For an overview of default available (and thus extendable) actionHandlers see the handlers folder in your atk directory.

Revision as of 08:14, 16 July 2010

ATK Howto: Using custom action handlers

Complexity: Advanced
Author: Rene Bakx <rene@nospamformeplease.71media.net>

List of other Howto's

Using the atkActionHandler to extend a handler

Note: This page uses features that require version 6.5 or higher.

Every action, like export, add, delete etc, within a node can be extended to use your own action. In this case we use it to change the behaviour of the export action.

Use case: you want the behaviour of the export action in ATK, but you want to tweak it slightly.

Adding a handler to your node

At the top of your node file, add the following lines:

// Import the class definition of myExportHandler
atkimport("mymodule.myExportHandler");

// Register the export handler class 
atkRegisterNodeHandler('myNode', 'export', new myExportHandler());

Where the mymodule is ofcourse your module folder, the myExportHandler the name of your handler.

The atkRegisterNodeHandler also takes a * as first parameter to match all the nodes in the scope, if you hook the node handler in your own extended atkNode for example.

The myExportHandler class is an extended atkActionHandler where some of the functions where overloaded, but the third parameter can also be a static method with two parameters (see atknode.Callhandler method).

A sample myExportHandler class could look like this:

class myExportHandler extends atkExportHandler // extend the default exporting functionality
{
  public function ..... // override whichever function you want to change
}

For an overview of default available (and thus extendable) actionHandlers see the handlers folder in your atk directory.