new handle trigger method

This commit is contained in:
x 2020-09-21 09:29:52 +02:00
parent d5d187c793
commit 2fbb6b1125

View File

@ -102,6 +102,22 @@ class InterfaceMyModuleTriggers extends DolibarrTriggers
// Put here code you want to execute when a Dolibarr business events occurs.
// Data and type of action are stored into $object and $action
/**
* new method to handle triggers
* you can now create a method for the interface
* this method should be named like the trigger in camelCase
* for example : COMPANY_CREATE => public function companyCreate($action, $object, User $user, Translate $langs, Conf $conf)
*/
$methodName = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($action)))));
$callback = array($this, $methodName);
if(is_callable($callback)){
dol_syslog(
"Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
);
return call_user_func($callback, $action, $object, $user, $langs, $conf);
};
switch ($action) {
// Users
//case 'USER_CREATE':