Merge pull request #19413 from FHenry/dev_add_hook_marginDisplay

new: add hook for displayMarginInfos
This commit is contained in:
Laurent Destailleur 2021-11-18 20:05:32 +01:00 committed by GitHub
commit 8b1c45d0fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 69 deletions

View File

@ -230,7 +230,8 @@ class HookManager
'setContentSecurityPolicy', 'setContentSecurityPolicy',
'setHtmlTitle', 'setHtmlTitle',
'completeTabsHead', 'completeTabsHead',
'formDolBanner' 'formDolBanner',
'displayMarginInfos',
) )
)) { )) {
$hooktype = 'addreplace'; $hooktype = 'addreplace';

View File

@ -201,7 +201,7 @@ class FormMargin
*/ */
public function displayMarginInfos($object, $force_price = false) public function displayMarginInfos($object, $force_price = false)
{ {
global $langs, $conf, $user; global $langs, $conf, $user, $hookmanager;
if (!empty($user->socid)) { if (!empty($user->socid)) {
return; return;
@ -213,6 +213,11 @@ class FormMargin
$marginInfo = $this->getMarginInfosArray($object, $force_price); $marginInfo = $this->getMarginInfosArray($object, $force_price);
$parameters=array('marginInfo'=>$marginInfo);
$reshook = $hookmanager->executeHooks('displayMarginInfos', $parameters, $object, $action);
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
} elseif (empty($reshook)) {
if (!empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) { // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better if (!empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) { // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better
print $langs->trans('ShowMarginInfos') . ' : '; print $langs->trans('ShowMarginInfos') . ' : ';
$hidemargininfos = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW']); // Clean cookie $hidemargininfos = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW']); // Clean cookie
@ -294,7 +299,11 @@ class FormMargin
} }
print '</tr>'; print '</tr>';
} }
print $hookmanager->resPrint;
print '</table>'; print '</table>';
print '</div>'; print '</div>';
} elseif ($reshook > 0) {
print $hookmanager->resPrint;
}
} }
} }