Jump to content

Including modifiers when extending nodes: Difference between revisions

From NusaATK
Juneih (talk | contribs)
No edit summary
Juneih (talk | contribs)
No edit summary
Line 3: Line 3:
This howto explains how you can include modifiers when you extend a node.  
This howto explains how you can include modifiers when you extend a node.  


All modifiers added to a node will be run in the node's init function. Which modifiers that runs however, depends on the m_type of a node, which will be different for any node that extends it. In order to have the modifiers run, some changes has to be made in the extended nodes init node.  
All modifiers added to a node runs 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.
 
<span style="color: #000000; font-style: italic;">
$this->atkNode("nodename");
</span>
 
In order to have the modifiers run, some changes has to be made in the extended nodes init node.  


<p></p>
<p></p>
An example init_node:
The following is an example init_node for a node that extends the hours node:
<p></p>
<p></p>


Line 36: Line 42:
</span>
</span>


This example is for running the modifiers added to the hours modules, this can of course be exchanged for any other node. The function itself is put in the extending node.  
As mentioned before, this example is for running the modifiers added to the hours modules, but this can of course be exchanged for any other node. In fact, the only thing that needs to be changed in this code is the 'hours' part! Remember, the function itself is put in the extending node.  


The result of including this is that you now will have access to all the attributes added by modifiers to the node that is extended.  
The result of including this is that you now will have access to all the attributes added by modifiers to the node that is extended.  

Revision as of 15:37, 23 November 2006

ATK Howto: Including modifiers when extending nodes

Complexity: easy
Author: June Henriksen <juneih@linpro.no>

List of other Howto's

This howto explains how you can include modifiers when you extend a node.

All modifiers added to a node runs 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 nodes init node.

The following is an example init_node for a node that extends the 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 = &getModule($modulename);
       $module->modifier($this);
     }
   }
   $this->m_module=$oldmodule;
   $this->m_type = $oldtype;
   return $ret;
 }

As mentioned before, this example is for running the modifiers added to the hours modules, but this can of course be exchanged for any other node. In fact, the only thing that needs to be changed in this code is the 'hours' part! Remember, the function itself is put in the extending node.

The result of including this is that you now will have access to all the attributes added by modifiers to the node that is extended.

--juneih 16:29, 23 November 2006 (CEST)