fix save using template

This commit is contained in:
John BOTELLA 2021-10-30 16:36:51 +02:00
parent 5179f2c90b
commit cdf1538ffa
2 changed files with 64 additions and 14 deletions

View File

@ -183,6 +183,24 @@ class formSetup
return true; 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 * Reload for each item default conf
* note: this will override custom configuration * note: this will override custom configuration
@ -396,7 +414,7 @@ class formSetupItem
} elseif ($this->type == 'product') { } elseif ($this->type == 'product') {
if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) { if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
$selected = (empty($this->fieldValue) ? '' : $this->fieldValue); $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 { } else {
$out.= '<input name="'.$this->confKey.'" class="flat '.(empty($this->cssClass) ? 'minwidth200' : $this->cssClass).'" value="'.$this->fieldValue.'">'; $out.= '<input name="'.$this->confKey.'" class="flat '.(empty($this->cssClass) ? 'minwidth200' : $this->cssClass).'" value="'.$this->fieldValue.'">';
@ -501,75 +519,94 @@ class formSetupItem
/** /**
* Set type of input as string * Set type of input as string
* @return null * @return self
*/ */
public function setAsString() public function setAsString()
{ {
$this->type = 'string'; $this->type = 'string';
return $this;
} }
/** /**
* Set type of input as textarea * Set type of input as textarea
* @return null * @return self
*/ */
public function setAsTextarea() public function setAsTextarea()
{ {
$this->type = 'textarea'; $this->type = 'textarea';
return $this;
} }
/** /**
* Set type of input as html editor * Set type of input as html editor
* @return null * @return self
*/ */
public function setAsHtml() public function setAsHtml()
{ {
$this->type = 'html'; $this->type = 'html';
return $this;
} }
/** /**
* Set type of input as emailtemplate selector * 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 * Set type of input as thirdparty_type selector
* @return null * @return self
*/ */
public function setAsThirdpartyType() public function setAsThirdpartyType()
{ {
$this->type = 'thirdparty_type'; $this->type = 'thirdparty_type';
return $this;
} }
/** /**
* Set type of input as Yes * Set type of input as Yes
* @return null * @return self
*/ */
public function setAsYesNo() public function setAsYesNo()
{ {
$this->type = 'yesno'; $this->type = 'yesno';
return $this;
} }
/** /**
* Set type of input as secure key * Set type of input as secure key
* @return null * @return self
*/ */
public function setAsSecureKey() public function setAsSecureKey()
{ {
$this->type = 'securekey'; $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 * Set type of input as a category selector
* TODO add default value * TODO add default value
* @param int $catType Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode (0, 1, 2, ...) is deprecated. * @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) public function setAsCategory($catType)
{ {
$this->type = 'category:'.$catType; $this->type = 'category:'.$catType;
return $this;
} }
} }

View File

@ -94,22 +94,33 @@ $formSetup->addItemsFromParamsArray($arrayofparameters);
// Hôte // Hôte
$item = $formSetup->newItem('NO_PARAM_JUST_TEXT'); $item = $formSetup->newItem('NO_PARAM_JUST_TEXT');
$item->fieldOverride = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST']; $item->fieldOverride = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'];
$item->cssClass = 'minwidth500';
// Setup conf MYMODULE_MYPARAM1 as a simple string input // Setup conf MYMODULE_MYPARAM1 as a simple string input
$item = $formSetup->newItem('MYMODULE_MYPARAM1'); $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 = $formSetup->newItem('MYMODULE_MYPARAM2');
$item->nameText = $item->getNameText().' more html text '; $item->nameText = $item->getNameText().' more html text ';
// Setup conf MYMODULE_MYPARAM3 // Setup conf MYMODULE_MYPARAM3
$item = $formSetup->newItem('MYMODULE_MYPARAM3'); $item = $formSetup->newItem('MYMODULE_MYPARAM3');
$item->setAsThirdpartyType(); $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(); $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; $error = 0;
$setupnotempty = 0; $setupnotempty = 0;
@ -121,6 +132,8 @@ $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
*/ */
if ((float) DOL_VERSION >= 6) { if ((float) DOL_VERSION >= 6) {
// TODO Add save setup by formSetup
$arrayofparameters = $formSetup->exportItemsAsParamsArray();
include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
$formSetup->reloadConfs(); $formSetup->reloadConfs();
} }