NEW Add hook "formatNotificationMessage"

This commit is contained in:
Laurent Destailleur 2017-01-09 23:54:31 +01:00
parent 93ab224614
commit 5c233a41b3
2 changed files with 30 additions and 5 deletions

View File

@ -116,8 +116,8 @@ class HookManager
* @param array $parameters Array of parameters * @param array $parameters Array of parameters
* @param Object $object Object to use hooks on * @param Object $object Object to use hooks on
* @param string $action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...) * @param string $action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
* @return mixed For 'addreplace hooks (doActions,formObjectOptions,pdf_xxx,...): Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results and set into ->resArray. * @return mixed For 'addreplace' hooks (doActions,formObjectOptions,pdf_xxx,...): Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller.
* For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...): Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results and set into ->resArray. * For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...): Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results bu hook and set into ->resArray for caller.
* All types can also return some values into an array ->results. * All types can also return some values into an array ->results.
* $this->error or this->errors are also defined by class called by this function if error. * $this->error or this->errors are also defined by class called by this function if error.
*/ */
@ -142,6 +142,7 @@ class HookManager
'formObjectOptions', 'formObjectOptions',
'formattachOptions', 'formattachOptions',
'formBuilddocLineOptions', 'formBuilddocLineOptions',
'formatNotificationMessage',
'getFormMail', 'getFormMail',
'getIdProfUrl', 'getIdProfUrl',
'moveUploadedFile', 'moveUploadedFile',

View File

@ -278,11 +278,19 @@ class Notify
*/ */
function send($notifcode, $object) function send($notifcode, $object)
{ {
global $user,$conf,$langs,$mysoc,$dolibarr_main_url_root; global $user,$conf,$langs,$mysoc;
global $hookmanager;
global $dolibarr_main_url_root;
if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0; if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0;
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
if (! is_object($hookmanager))
{
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager=new HookManager($this->db);
}
$hookmanager->initHooks(array('notification'));
dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id); dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id);
@ -443,6 +451,14 @@ class Notify
$message.= $mesg; $message.= $mesg;
if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); if ($link) $message=dol_concatdesc($message,$urlwithroot.$link);
$parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename);
$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
{
if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
}
$mailfile = new CMailFile( $mailfile = new CMailFile(
$subject, $subject,
$sendto, $sendto,
@ -637,6 +653,14 @@ class Notify
if ($sendto) if ($sendto)
{ {
$parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename);
$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
{
if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
}
$mailfile = new CMailFile( $mailfile = new CMailFile(
$subject, $subject,
$sendto, $sendto,