Including modifiers when extending nodes: Difference between revisions
No edit summary |
mNo edit summary |
||
| Line 36: | Line 36: | ||
foreach ($g_modifiers[$this->atknodetype()] as $modulename) | foreach ($g_modifiers[$this->atknodetype()] as $modulename) | ||
{ | { | ||
$module = | $module =</syntaxhighlight> | ||
</syntaxhighlight> | |||
Revision as of 13:18, 14 July 2007
|
ATK Howto: Including modifiers when extending nodes
|
Intro
ATK features a concept called 'modifiers' that allows one to change functionality of a node without touching the original code of the node (See the 'Using modifiers' howto).
The way modifiers work however, prevents modifiers from being applied to classes that extend the node. This may be fixed in a later version of ATK. For now, you can use this howto which presents a workaround to this problem.
Adding modifiers to derived nodes
All modifiers added to a node run from the node's init function. Which modifiers that runs however, depends on the m_type of a node. When you extend a node, you get a new m_type if you set the atkNode in the constructor.
$this->atkNode("nodename");
In order to have the modifiers run, some changes has to be made in the extended node's init node.
The following is an example init_node for a node that extends the timereg.hours node:
function init()
{
$ret = parent::init();
$oldtype = $this->m_type;
$oldmodule= $this->m_module;
$this->m_type='hours';
$this->m_module='timereg';
global $g_modifiers;
if (isset($g_modifiers[$this->atknodetype()]))
{
foreach ($g_modifiers[$this->atknodetype()] as $modulename)
{
$module =