Changes

m
Line 105: Line 105:  
=Manage and create a new trigger's action=
 
=Manage and create a new trigger's action=
   −
To manage other events on objects than the one defined before, you must edit the Dolibarr code to add the following code inside the business method of the class file of the object:
+
To manage events other than those above, you must modify the Dolibarr code to add the following sequence in the business methods of the classes of the objects handled:
   −
<source lang="php">
+
<source lang = "php">
// Call triggers
  −
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  −
$interface=new Interfaces($this->db);
  −
$result=$interface->run_triggers('XXXXX_YYYYY',$this,$user,$langs,$conf);
  −
if ($result < 0) { $error++; $this->errors=$interface->errors; }
  −
// End call triggers
  −
</source>
  −
'''With Dolibarr >= 3.7 you must use this piece of code for new trigger :'''
  −
<source lang="php">
   
// Call trigger
 
// Call trigger
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+
$result = $this->call_trigger('XXXXX_YYYYY', $user);
$interface=new Interfaces($this->db);
+
if ($result <0) $error++;
$result=$this->call_trigger('XXXXX_YYYYY',$user); // this is the new way to call triggers with Dolibarr >= 3.7.0
  −
if ($result < 0) { $error++; $this->errors=$interface->errors; }
   
// End call triggers
 
// End call triggers
 
</source>
 
</source>
   −
Here, '''$this''' contains the business class with all information to send to the trigger functions. Replace 'XXXXX_YYYYY' by an event code not already used.
+
It will then be possible to add in the run_trigger method of any trigger file, an if which allows you to manage this code. The run_trigger method would then be of the form:
Then you will be able to add inside the run_trigger method, a "if" to manage this code. The run_trigger method will contains a part of code like this :
      
<source lang="php">
 
<source lang="php">