439
edits
(Added more infos about the const update) |
|||
| Line 4: | Line 4: | ||
On the contrary to the triggers (another feature to interact with Dolibarr code) which are by definition linked to a business action, hooks can happen anywhere at anytime, they are an entry point into the program. | On the contrary to the triggers (another feature to interact with Dolibarr code) which are by definition linked to a business action, hooks can happen anywhere at anytime, they are an entry point into the program. | ||
* Hooks work by context (ie the module, eg: "productcard" for products, "invoicecard" for invoices, etc..). It's easy to find them, just search for "'''callHooks('''" | * Hooks work by context (ie the module, eg: "productcard" for products, "invoicecard" for invoices, etc..). It's easy to find them, just search for "'''callHooks('''" | ||
* Hooks are functions that can be overloaded by your own. You decide if your code is added to standard Dolibarr code or if it replace Dolibarr code. | * Hooks are functions that can be overloaded by your own. You decide if your code is added to standard Dolibarr code or if it replace Dolibarr code. You can find overloadable functions by searching for "'''executeHooks('''" | ||
| Line 24: | Line 24: | ||
Then you get the value at the third index, which is a string with contexts separated by a comma. | Then you get the value at the third index, which is a string with contexts separated by a comma. | ||
<source lang="php"> | |||
[b]IMPORTANT[/b]: Be careful: do not forget to DISABLE then RENABLE the module in the admin panel to accept the now const values, because these constants are only added to the database when enabling the module. | |||
And please note that the const are updated because there is the remove() function (in the same file) that tells Dolibarr to remove the constants when disabling the module, else Dolibarr would not update the constants if they were not removed first (even if the values changed). Your remove() function should be something similar to this: | |||
[code] | |||
/** | |||
* Function called when module is disabled. | |||
* Remove from database constants, boxes and permissions from Dolibarr database. | |||
* Data directories are not deleted. | |||
* @return int 1 if OK, 0 if KO | |||
*/ | |||
function remove() | |||
{ | |||
$sql = array("DELETE FROM ".MAIN_DB_PREFIX."const WHERE name like '%_mymodulename' OR name like '%_mymodulename_%';"); | |||
return $this->_remove($sql); | |||
} | |||
[/code] | |||
</source> | |||
2- You will overload a hook (a function) with your own. | 2- You will overload a hook (a function) with your own. | ||
edits