Line 13:
Line 13:
You can also use triggers to modify the behavior of Dolibarr itself: for example, to create a contract automatically when an invoice is validated, a fill a log file when a record is deleted, ...
You can also use triggers to modify the behavior of Dolibarr itself: for example, to create a contract automatically when an invoice is validated, a fill a log file when a record is deleted, ...
−
Note that triggers is a feature for developers that is limited to business CRUD events (Create | Read | Update | Delete). There is another feature for developers to inject custom code in the application called the [[Hooks system]].
+
Note that triggers is a feature for developers that is limited to:
+
* business CRUD events (Create | Read | Update | Delete).
+
* change of the primary status of objects
+
There is another feature for developers to inject custom code in the application called the [[Hooks system]]. Note, for historic reason, when you send an email, this generates also a trigger call even if this case is not among the 2 allowed.
+
So, to add your own code that will be triggered by a Dolibarr trigger, this is the process:
So, to add your own code that will be triggered by a Dolibarr trigger, this is the process:
Line 28:
Line 32:
This new file must be saved inside same directory.
This new file must be saved inside same directory.
−
Note: Value you can use for mod MyModule are values found in directory
+
Note: Value you can use for modMyModule are values found in directory
−
''htdocs/includes/modules''.
+
''htdocs/core/modules''.
'''WARNING''': All those parameters are necessary for the trigger to be detected and executed! Eg: if you forget the priority number, your trigger won't be detected!
'''WARNING''': All those parameters are necessary for the trigger to be detected and executed! Eg: if you forget the priority number, your trigger won't be detected!
For example, you can name your new trigger file:
For example, you can name your new trigger file:
−
''htdocs/includes/triggers/interface_99_modFacture_Myworkflow.class.php''
+
''htdocs/core/triggers/interface_99_modFacture_Myworkflow.class.php''
By creating such a file with a name like the example, your new trigger file will be executed each time a Dolibarr business event occurs but only if the module Facture is enabled.
By creating such a file with a name like the example, your new trigger file will be executed each time a Dolibarr business event occurs but only if the module Facture is enabled.
−
'''Note''': If you develop a full module, you can also place the trigger file in your own module's subdirectly. Eg: if your module resides in htdocs/mymodule/, then you can place your triggers inside htdocs/mymodule/core/triggers/. But for this, you must declare the trigger into your module descriptor file (eg: '''/mymodule/core/modules/modMyModule.class.php'''). For this, add into this file triggers->1 into module_parts array:
+
'''Note''': If you develop a full module, you can also place the trigger file in your own module's sub-directory. Eg: if your module resides in htdocs/mymodule/, then you can place your triggers inside htdocs/mymodule/core/triggers/. But for this, you must declare the trigger into your module descriptor file (eg: '''/mymodule/core/modules/modMyModule.class.php'''). For this, add into this file triggers->1 into module_parts array:
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
// Defined all module parts (triggers, login, substitutions, menus, etc...) (0=disable,1=enable)
// Defined all module parts (triggers, login, substitutions, menus, etc...) (0=disable,1=enable)
Line 50:
Line 54:
−
2) Edit the file ''interface_99_modMyModule_Myworkflow.class.php'' to rename class ''InterfaceMyModuleTriggers'' by ''InterfaceMyworkflow''
+
2) Edit the file ''interface_99_modFacture_Myworkflow.class.php'' to modify its content by changing the class ''InterfaceMyModuleTriggers'' by ''InterfaceMyworkflow:''
Then go on page Home -> Admin Tools -> About Dolibarr ->Triggers.
Then go on page Home -> Admin Tools -> About Dolibarr ->Triggers.