From cdf1538ffacac651367a423cffce3b83d0c93ec9 Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Sat, 30 Oct 2021 16:36:51 +0200 Subject: [PATCH] fix save using template --- htdocs/core/class/html.formsetup.class.php | 59 +++++++++++++++---- htdocs/modulebuilder/template/admin/setup.php | 19 +++++- 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index f229d12101d..eb5a9710da1 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -183,6 +183,24 @@ class formSetup return true; } + /** + * used to export param array for /core/actions_setmoduleoptions.inc.php template + * @return array $arrayofparameters for /core/actions_setmoduleoptions.inc.php + * @deprecated + */ + public function exportItemsAsParamsArray() + { + $arrayofparameters = array(); + foreach ($this->params as $key => $item) { + $arrayofparameters[$item->confKey] = array( + 'type' => $item->type, + 'enabled' => $item->enabled + ); + } + + return $arrayofparameters; + } + /** * Reload for each item default conf * note: this will override custom configuration @@ -396,7 +414,7 @@ class formSetupItem } elseif ($this->type == 'product') { if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) { $selected = (empty($this->fieldValue) ? '' : $this->fieldValue); - $this->form->select_produits($selected, $this->confKey, '', 0); + $out.= $this->form->select_produits($selected, $this->confKey, '', 0, 0, 1, 2, '', 0, array(), 0, '1', 0, $this->cssClass, 0, '', null, 1); } } else { $out.= ''; @@ -501,75 +519,94 @@ class formSetupItem /** * Set type of input as string - * @return null + * @return self */ public function setAsString() { $this->type = 'string'; + return $this; } /** * Set type of input as textarea - * @return null + * @return self */ public function setAsTextarea() { $this->type = 'textarea'; + return $this; } /** * Set type of input as html editor - * @return null + * @return self */ public function setAsHtml() { $this->type = 'html'; + return $this; } /** * Set type of input as emailtemplate selector - * @return null + * @param string $templateType email template type + * @return self */ - public function setAsEmailTemplate() + public function setAsEmailTemplate($templateType) { - $this->type = 'emailtemplate'; + $this->type = 'emailtemplate:'.$templateType; + return $this; } /** * Set type of input as thirdparty_type selector - * @return null + * @return self */ public function setAsThirdpartyType() { $this->type = 'thirdparty_type'; + return $this; } /** * Set type of input as Yes - * @return null + * @return self */ public function setAsYesNo() { $this->type = 'yesno'; + return $this; } /** * Set type of input as secure key - * @return null + * @return self */ public function setAsSecureKey() { $this->type = 'securekey'; + return $this; + } + + /** + * Set type of input as product + * @return self + */ + public function setAsProduct() + { + $this->type = 'product'; + return $this; } /** * Set type of input as a category selector * TODO add default value * @param int $catType Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode (0, 1, 2, ...) is deprecated. - * @return null + * @return self */ public function setAsCategory($catType) { $this->type = 'category:'.$catType; + return $this; } } diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index f7f30c19228..007e9d84b12 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -94,22 +94,33 @@ $formSetup->addItemsFromParamsArray($arrayofparameters); // Hôte $item = $formSetup->newItem('NO_PARAM_JUST_TEXT'); $item->fieldOverride = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST']; +$item->cssClass = 'minwidth500'; + // Setup conf MYMODULE_MYPARAM1 as a simple string input $item = $formSetup->newItem('MYMODULE_MYPARAM1'); -// // Setup conf MYMODULE_MYPARAM1 as a simple textarea input but we replace the text of field title +// Setup conf MYMODULE_MYPARAM1 as a simple textarea input but we replace the text of field title $item = $formSetup->newItem('MYMODULE_MYPARAM2'); $item->nameText = $item->getNameText().' more html text '; - // Setup conf MYMODULE_MYPARAM3 $item = $formSetup->newItem('MYMODULE_MYPARAM3'); $item->setAsThirdpartyType(); -// Setup conf MYMODULE_MYPARAM4 : quick define write style +// Setup conf MYMODULE_MYPARAM4 : exemple of quick define write style $formSetup->newItem('MYMODULE_MYPARAM4')->setAsYesNo(); +// Setup conf MYMODULE_MYPARAM5 +$formSetup->newItem('MYMODULE_MYPARAM5')->setAsEmailTemplate('thirdparty'); + +// Setup conf MYMODULE_MYPARAM6 +$formSetup->newItem('MYMODULE_MYPARAM6')->setAsSecureKey()->enabled = 0; // disabled + +// Setup conf MYMODULE_MYPARAM7 +$formSetup->newItem('MYMODULE_MYPARAM7')->setAsProduct(); + + $error = 0; $setupnotempty = 0; @@ -121,6 +132,8 @@ $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); */ if ((float) DOL_VERSION >= 6) { + // TODO Add save setup by formSetup + $arrayofparameters = $formSetup->exportItemsAsParamsArray(); include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; $formSetup->reloadConfs(); }