From bb294eef95133ace830772a3ccb2d3534701876d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 18 Jul 2025 02:59:19 +0200 Subject: [PATCH] NEW add hook getListOfModels (#34626) * add hook getListOfModels * Update functions2.lib.php * Update functions2.lib.php --------- Co-authored-by: Laurent Destailleur --- htdocs/core/lib/functions2.lib.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index b362f201efd..13de237e636 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1965,8 +1965,9 @@ function version_webserver() */ function getListOfModels($db, $type, $maxfilenamelength = 0) { - global $conf, $langs; - $liste = array(); + global $conf, $hookmanager, $langs; + + $docmodels = array(); $found = 0; $dirtoscan = ''; @@ -2017,21 +2018,21 @@ function getListOfModels($db, $type, $maxfilenamelength = 0) if (count($listoffiles)) { foreach ($listoffiles as $record) { $max = ($maxfilenamelength ? $maxfilenamelength : 28); - $liste[$obj->id.':'.$record['fullname']] = dol_trunc($record['name'], $max, 'middle'); + $docmodels[$obj->id.':'.$record['fullname']] = dol_trunc($record['name'], $max, 'middle'); } } else { - $liste[0] = $obj->label.': '.$langs->trans("None"); + $docmodels[0] = $obj->label.': '.$langs->trans("None"); } } else { if ($type == 'member' && $obj->doc_template_name == 'standard') { // Special case, if member template, we add variant per format global $_Avery_Labels; include_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php'; foreach ($_Avery_Labels as $key => $val) { - $liste[$obj->id.':'.$key] = ($obj->label ? $obj->label : $obj->doc_template_name).' '.$val['name']; + $docmodels[$obj->id.':'.$key] = ($obj->label ? $obj->label : $obj->doc_template_name).' '.$val['name']; } } else { // Common usage - $liste[$obj->id] = $obj->label ? $obj->label : $obj->doc_template_name; + $docmodels[$obj->id] = $obj->label ? $obj->label : $obj->doc_template_name; } } $i++; @@ -2040,9 +2041,18 @@ function getListOfModels($db, $type, $maxfilenamelength = 0) dol_print_error($db); return -1; } - + $parameters = array( + 'list' => &$docmodels, + 'found' => &$found, + 'type' => $type, + 'maxfilenamelength' => $maxfilenamelength, + ); + $reshook = $hookmanager->executeHooks('getListOfModels', $parameters); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } if ($found) { - return $liste; + return $docmodels; } else { return 0; }