diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index d610203b3ad..8384886e50c 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -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 { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 884b5ece6f7..54ef73f19d6 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -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); } }