Hooks system: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 11: Line 11:
To use a hook (overload a function), you first need to already have defined a module (see the wiki for that), and then you need to do 2 things:
To use a hook (overload a function), you first need to already have defined a module (see the wiki for that), and then you need to do 2 things:


1- to add your module to the hooks of the context you want to hook on.
1- add your module to the hooks of the context you want to hook on.
This means that when this context (module) will happen, your module will be called.
This means that when this context will happen, your module hook code will be called.
To do that, just edit your /htdocs/includes/modYourModuleName.class.php and edit the $this->const variable with something like this:
To do that, just edit your /htdocs/core/modules/modYourModuleName.class.php and edit the $this->module_parts variable with something like this:
 
<source lang="php">
<source lang="php">
$this->const = array(
$this->module_parts = array(
0=>array('MAIN_MODULE_YOURMODULENAME_HOOKS', 'chaine', 'productcard:invoicecard:propalcard',
'hooks' => array('hookcontext1','hookcontext2')  // Set here all hooks context managed by module
'Hooks list for managing printing functions of the CustomFields module', 0, 'current', 1)
);
);
</source>
</source>
Note: format of a const declaration:
<source lang="php">
$key=>array($const_name,$type,$value,$description,$visible_on_admin_panel=0,$entity='current',$deleteonunactive=0),
$key2=>...
</source>
With $key being a positive integer.


Of course change YourModuleName with your own module's name.
Of course change YourModuleName with your own module's name.

Navigation menu