From 6aaf0f46554ae80bdf9722966a27b0c167f7f02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20J?= Date: Mon, 19 Nov 2018 17:40:16 +0100 Subject: [PATCH 1/3] Add afterSelectOptions hook & selectcontacts context --- htdocs/core/class/html.form.class.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 9a1ac5cb834..7787305e965 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1389,6 +1389,8 @@ class Form * Return HTML code of the SELECT of list of all contacts (for a third party or all). * This also set the number of contacts found into $this->num * + * @since 8.0 Add afterSelectOptions hook & selectcontacts context. + * * @param int $socid Id ot third party or 0 for all or -1 for empty list * @param array|int $selected Array of ID of pre-selected contact id * @param string $htmlname Name of HTML field ('none' for a not editable field) @@ -1408,7 +1410,7 @@ class Form */ function selectcontacts($socid, $selected='', $htmlname='contactid', $showempty=0, $exclude='', $limitto='', $showfunction=0, $moreclass='', $options_only=false, $showsoc=0, $forcecombo=0, $events=array(), $moreparam='', $htmlid='', $multiple=false) { - global $conf,$langs; + global $conf,$langs,$hookmanager,$action; $langs->load('companies'); @@ -1418,6 +1420,14 @@ class Form else if (!is_array($selected)) $selected = array($selected); $out=''; + // Add selectcontacts hook + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('selectcontacts')); + // On recherche les societes $sql = "SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste"; if ($showsoc > 0) $sql.= " , s.nom as company"; @@ -1503,6 +1513,18 @@ class Form $out.= ($socid != -1) ? ($langs->trans($socid?"NoContactDefinedForThirdParty":"NoContactDefined")) : $langs->trans('SelectAThirdPartyFirst'); $out.= ''; } + + $parameters = array( + 'socid'=>$socid, + 'htmlname'=>$htmlname, + 'resql'=>$resql, + 'out'=>&$out, + 'showfunction'=>$showfunction, + 'showsoc'=>$showsoc, + ); + + $reshook = $hookmanager->executeHooks( 'afterSelectOptions', $parameters, $this, $action ); // Note that $action and $object may have been modified by some hooks + if ($htmlname != 'none' || $options_only) { $out.= ''; From 37f3b8bbde5902afb10480d6fdd762f8fe10ad8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20J?= Date: Mon, 19 Nov 2018 17:51:00 +0100 Subject: [PATCH 2/3] Update @since version to 9.0 --- htdocs/core/class/html.form.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 7787305e965..f7f2462b604 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1389,7 +1389,7 @@ class Form * Return HTML code of the SELECT of list of all contacts (for a third party or all). * This also set the number of contacts found into $this->num * - * @since 8.0 Add afterSelectOptions hook & selectcontacts context. + * @since 9.0 Add afterSelectOptions hook & selectcontacts context. * * @param int $socid Id ot third party or 0 for all or -1 for empty list * @param array|int $selected Array of ID of pre-selected contact id From 89909ebab0ae6f596b6126b23817809d37880486 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 14 Dec 2018 17:32:41 +0100 Subject: [PATCH 3/3] Update html.form.class.php --- htdocs/core/class/html.form.class.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index f7f2462b604..0de5934b0c5 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1389,7 +1389,7 @@ class Form * Return HTML code of the SELECT of list of all contacts (for a third party or all). * This also set the number of contacts found into $this->num * - * @since 9.0 Add afterSelectOptions hook & selectcontacts context. + * @since 9.0 Add afterSelectContactOptions hook * * @param int $socid Id ot third party or 0 for all or -1 for empty list * @param array|int $selected Array of ID of pre-selected contact id @@ -1418,17 +1418,15 @@ class Form if ($selected === '') $selected = array(); else if (!is_array($selected)) $selected = array($selected); - $out=''; + $out=''; - // Add selectcontacts hook if (! is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; $hookmanager=new HookManager($this->db); } - $hookmanager->initHooks(array('selectcontacts')); - // On recherche les societes + // We search third parties $sql = "SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste"; if ($showsoc > 0) $sql.= " , s.nom as company"; $sql.= " FROM ".MAIN_DB_PREFIX ."socpeople as sp"; @@ -1523,7 +1521,7 @@ class Form 'showsoc'=>$showsoc, ); - $reshook = $hookmanager->executeHooks( 'afterSelectOptions', $parameters, $this, $action ); // Note that $action and $object may have been modified by some hooks + $reshook = $hookmanager->executeHooks( 'afterSelectContactOptions', $parameters, $this, $action ); // Note that $action and $object may have been modified by some hooks if ($htmlname != 'none' || $options_only) {