From b0816499078338f8c20c484f20f8395daf2528ab Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Fri, 20 May 2022 22:05:13 +0200 Subject: [PATCH 1/2] Fix fatal error and missing param --- htdocs/core/class/html.formsetup.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index b26438fd9e9..a69135454df 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -653,7 +653,7 @@ class FormSetupItem public function saveConfValue() { if (!empty($this->saveCallBack) && is_callable($this->saveCallBack)) { - return call_user_func($this->saveCallBack); + return call_user_func($this->saveCallBack, $this); } // Modify constant only if key was posted (avoid resetting key to the null value) @@ -1013,6 +1013,7 @@ class FormSetupItem } $out.= $this->langs->trans($template->label); } elseif (preg_match('/category:/', $this->type)) { + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $c = new Categorie($this->db); $result = $c->fetch($this->fieldValue); if ($result < 0) { From c3e3eab5942799ef8ac14ec80e714e154838f9ed Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Fri, 20 May 2022 22:34:44 +0200 Subject: [PATCH 2/2] Fix missing hooks and fatal error --- htdocs/core/class/html.formsetup.class.php | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index a69135454df..1ee9812f4fd 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -240,10 +240,24 @@ class FormSetup * saveConfFromPost * * @param bool $noMessageInUpdate display event message on errors and success - * @return void|null + * @return int -1 if KO, 1 if OK */ public function saveConfFromPost($noMessageInUpdate = false) { + global $hookmanager; + + $parameters = array(); + $reshook = $hookmanager->executeHooks('formSetupBeforeSaveConfFromPost', $parameters, $this); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) { + $this->setErrors($hookmanager->errors); + return -1; + } + + if ($reshook > 0) { + return $reshook; + } + + if (empty($this->items)) { return null; } @@ -265,11 +279,13 @@ class FormSetup if (empty($noMessageInUpdate)) { setEventMessages($this->langs->trans("SetupSaved"), null); } + return 1; } else { $this->db->rollback(); if (empty($noMessageInUpdate)) { setEventMessages($this->langs->trans("SetupNotSaved"), null, 'errors'); } + return -1; } } @@ -652,6 +668,20 @@ class FormSetupItem */ public function saveConfValue() { + global $hookmanager; + + $parameters = array(); + $reshook = $hookmanager->executeHooks('formSetupBeforeSaveConfValue', $parameters, $this); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) { + $this->setErrors($hookmanager->errors); + return -1; + } + + if ($reshook > 0) { + return $reshook; + } + + if (!empty($this->saveCallBack) && is_callable($this->saveCallBack)) { return call_user_func($this->saveCallBack, $this); }