Changes

Jump to navigation Jump to search
m
Line 20: Line 20:  
This will find results such as "$reshook = $hookmanager->executeHooks('addMoreBoxStatsCustomer', $parameters, $object, $action);" where "addMoreBoxStatsCustomer" is the Hook name.
 
This will find results such as "$reshook = $hookmanager->executeHooks('addMoreBoxStatsCustomer', $parameters, $object, $action);" where "addMoreBoxStatsCustomer" is the Hook name.
   −
= Add a hook to insert code =
+
= Adding a hook point into code=
To implement a hook in your own module (so that your module can be ''hooked'' by others), you have two steps to follow.
+
To add a hook into a module (so that the module can be ''hooked'' by others), two code additions are required in each php script where you want to implement hooks. Hooks are implemented in Dolibarr core modules in the same manner.
 
  −
These steps must be followed for every php script of your module where you want to implement hooks. This is also how hooks are implemented in Dolibarr core modules.
        Line 35: Line 33:  
</source>
 
</source>
   −
$hookmanager->initHooks() takes 1 parameter (an array of contexts) and activate the hooks management for this script:
+
$hookmanager->initHooks() takes 1 parameter (an array of contexts) and activates the hooks management for this script:
   −
- ''''context'''' is a context string. This is simply a indicator that hooking functions can use to detect in which context they are called.
+
- ''''context'''' is a context string. This is simply a indicator that hooking functions can use, to detect in which context they are called.
   −
Note: you can set several contexts in the same init (for example if you want to have a common context into several pages and want also a specific context deidcated to your page).
+
Note: you can set several contexts in the same init (for example if you want to have a common context into several pages and want also a specific context dedicated to your page).
      Line 58: Line 56:  
- ''''hookname'''' is the hook's name as a string (can be anything you want, or you can follow the Dolibarr's nomenclatura, look at the list of hooks below). eg: 'formObjectOptions'
 
- ''''hookname'''' is the hook's name as a string (can be anything you want, or you can follow the Dolibarr's nomenclatura, look at the list of hooks below). eg: 'formObjectOptions'
   −
- '''$parameters''' is a custom array to send more custom data to the hook (the hooking function can then process it). Place here anything you want, it can be a file, an array of strings, anything...
+
- '''$parameters''' is a custom array to send data to the hook so the hooking function can process it. It can be a file, an array of strings, anything...
    
eg:
 
eg:
Line 65: Line 63:  
</source>
 
</source>
   −
- '''$object''' is the object you want to pass onto the hooking function, mainly the current module's data (eg: invoice object if it is invoice module, etc..). This can be anything you want, but remember this will be the main component hooking functions will be using.
+
- '''$object''' is the object you want to pass onto the hooking function, usually the current module's data (eg: the invoice object if it is invoice module, etc..). This can be anything you want, but remember this will be the main component hooking functions will be using.
    
- '''$action''' is a string indicating the current action (can be set to null or to something sensible like 'create' or 'edit').
 
- '''$action''' is a string indicating the current action (can be set to null or to something sensible like 'create' or 'edit').
98

edits

Navigation menu