From b8a80f931144a2ee979f815a23b333fac468f19c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Sat, 21 Jan 2017 17:30:35 +0100 Subject: [PATCH] Fix code comment and missing showLinkToObjectBlock hook declaration as an addreplace hook. --- htdocs/core/class/commonobject.class.php | 6 ++--- htdocs/core/class/hookmanager.class.php | 8 +++---- htdocs/core/class/html.form.class.php | 28 +++++++++++++++++++++--- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index b75bc9e3d05..7b48240a72b 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2554,9 +2554,9 @@ abstract class CommonObject if (! empty($this->linkedObjectsIds)) { - foreach($this->linkedObjectsIds as $objecttype => $objectids) + foreach($this->linkedObjectsIds as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...) { - // Parse element/subelement (ex: project_task) + // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) $module = $element = $subelement = $objecttype; if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) @@ -2621,7 +2621,7 @@ abstract class CommonObject if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) { dol_include_once('/'.$classpath.'/'.$classfile.'.class.php'); - //print '/'.$classpath.'/'.$classfile.'.class.php'; + //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); if (class_exists($classname)) { foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 739e635f85c..b860e083469 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -118,7 +118,7 @@ class HookManager * @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. * 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. - * All types can also return some values into an array ->results. + * All types can also return some values into an array ->results that will be finaly merged into this->resArray for caller. * $this->error or this->errors are also defined by class called by this function if error. */ function executeHooks($method, $parameters=false, &$object='', &$action='') @@ -172,11 +172,11 @@ class HookManager 'printObjectSubLine', 'createDictionaryFieldList', 'editDictionaryFieldlist', - 'getFormMail' + 'getFormMail', + 'showLinkToObjectBlock' ) )) $hooktype='addreplace'; - // Deprecated hook types ('returnvalue') - //if (preg_match('/^pdf_/',$method) && $method != 'pdf_writelinedesc') $hooktype='returnvalue'; // pdf_xxx except pdf_writelinedesc are 'returnvalue' hooks. When there is 2 hooks of this type, only last one win. TODO Move them into 'output' or 'addreplace' hooks. + if ($method == 'insertExtraFields') { $hooktype='returnvalue'; // deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available. diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e4049dd85ff..ab0999cfdb8 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5391,6 +5391,7 @@ class Form global $noMoreLinkedObjectBlockAfter; $noMoreLinkedObjectBlockAfter=1; } + $res=@include dol_buildpath($reldir.'/'.$tplname.'.tpl.php'); if ($res) { @@ -5439,7 +5440,27 @@ class Form 'order_supplier'=>array('enabled'=>$conf->fournisseur->commande->enabled , 'perms'=>1, 'label'=>'LinkToSupplierOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id), 'invoice_supplier'=>array('enabled'=>$conf->fournisseur->facture->enabled , 'perms'=>1, 'label'=>'LinkToSupplierInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id) ); - + + global $action; + + // Can complet the possiblelink array + $hookmanager->initHooks(array('commonobject')); + $parameters=array(); + $reshook=$hookmanager->executeHooks('showLinkToObjectBlock',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) + { + if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) + { + $possiblelinks=array_merge($possiblelinks, $hookmanager->resArray); + } + } + else if ($reshook > 0) + { + if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) + { + $possiblelinks=$hookmanager->resArray; + } + } foreach($possiblelinks as $key => $possiblelink) { @@ -5451,6 +5472,7 @@ class Form { print '<div id="'.$key.'list"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display:none"':'').'>'; $sql = $possiblelink['sql']; + $resqllist = $this->db->query($sql); if ($resqllist) { @@ -5466,7 +5488,7 @@ class Form print '<td class="nowrap"></td>'; print '<td align="center">' . $langs->trans("Ref") . '</td>'; print '<td align="left">' . $langs->trans("RefCustomer") . '</td>'; - print '<td align="left">' . $langs->trans("AmountHTShort") . '</td>'; + print '<td align="right">' . $langs->trans("AmountHTShort") . '</td>'; print '<td align="left">' . $langs->trans("Company") . '</td>'; print '</tr>'; while ($i < $num) @@ -5480,7 +5502,7 @@ class Form print '</td>'; print '<td align="center">' . $objp->ref . '</td>'; print '<td>' . $objp->ref_client . '</td>'; - print '<td>' . price($objp->total_ht) . '</td>'; + print '<td align="right">' . price($objp->total_ht) . '</td>'; print '<td>' . $objp->name . '</td>'; print '</tr>'; $i++; -- GitLab