Try a better fix for #18105

This commit is contained in:
Laurent Destailleur 2021-07-12 16:55:16 +02:00
parent a2de6c00a0
commit d3f324c2d4
2 changed files with 22 additions and 8 deletions

View File

@ -254,16 +254,29 @@ class HookManager
// Hooks that must return int (hooks with type 'addreplace')
if ($hooktype == 'addreplace')
{
$resaction += $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
if ($resaction < 0 || !empty($actionclassinstance->error) || (!empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0))
{
$resactiontmp = $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
$resaction += $resactiontmp;
if ($resactiontmp < 0 || !empty($actionclassinstance->error) || (!empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0)) {
$error++;
$this->error = $actionclassinstance->error; $this->errors = array_merge($this->errors, (array) $actionclassinstance->errors);
dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error) ? '' : " ".$this->error).(empty($this->errors) ? '' : " ".join(",", $this->errors)), LOG_ERR);
}
if (isset($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray = array_merge($this->resArray, $actionclassinstance->results);
if (!empty($actionclassinstance->resprints)) $this->resPrint .= $actionclassinstance->resprints;
if (isset($actionclassinstance->results) && is_array($actionclassinstance->results)) {
if ($resactiontmp > 0) {
$this->resArray = $actionclassinstance->results;
} else {
$this->resArray = array_merge($this->resArray, $actionclassinstance->results);
}
}
if (!empty($actionclassinstance->resprints)) {
if ($resactiontmp > 0) {
$this->resPrint = $actionclassinstance->resprints;
} else {
$this->resPrint .= $actionclassinstance->resprints;
}
}
}
// Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...)
else {

View File

@ -7754,11 +7754,12 @@ function complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type,
{
$parameters = array('object' => $object, 'mode' => $mode, 'head' => $head);
$reshook = $hookmanager->executeHooks('completeTabsHead', $parameters);
if ($reshook > 0)
{
if ($reshook > 0) { // Hook ask to replace completely the array
$head = $hookmanager->resArray;
$h = count($head);
} else { // Hook
$head = array_merge($head, $hookmanager->resArray);
}
$h = count($head);
}
}