Merge pull request #19508 from atm-john/fix_missing_formsetup_elements
Fix missing formsetup elements
This commit is contained in:
commit
fdf7749a54
@ -44,6 +44,41 @@ class FormSetup
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
protected $maxItemRank;
|
protected $maxItemRank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this is an html string display before output form
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $htmlBeforeOutputForm = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this is an html string display after output form
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $htmlAfterOutputForm = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this is an html string display on buttons zone
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $htmlOutputMoreButton = '';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $formAttributes = array(
|
||||||
|
'action' => '', // set in __construct
|
||||||
|
'method' => 'POST'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* an list of hidden inputs used only in edit mode
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $formHiddenInputs = array();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -55,6 +90,11 @@ class FormSetup
|
|||||||
global $langs;
|
global $langs;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->form = new Form($this->db);
|
$this->form = new Form($this->db);
|
||||||
|
$this->formAttributes['action'] = $_SERVER["PHP_SELF"];
|
||||||
|
|
||||||
|
$this->formHiddenInputs['token'] = newToken();
|
||||||
|
$this->formHiddenInputs['action'] = 'update';
|
||||||
|
|
||||||
|
|
||||||
if ($outputLangs) {
|
if ($outputLangs) {
|
||||||
$this->langs = $outputLangs;
|
$this->langs = $outputLangs;
|
||||||
@ -63,6 +103,27 @@ class FormSetup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an attributes string form an input array
|
||||||
|
* @param array $attributes an array of attributes keys and values,
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
static public function generateAttributesStringFromArray($attributes)
|
||||||
|
{
|
||||||
|
$Aattr = array();
|
||||||
|
if (is_array($attributes)) {
|
||||||
|
foreach ($attributes as $attribute => $value) {
|
||||||
|
if (is_array($value) || is_object($value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$Aattr[] = $attribute.'="'.dol_escape_htmltag($value).'"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return !empty($Aattr)?implode(' ', $Aattr):'';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $editMode true will display output on edit mod
|
* @param bool $editMode true will display output on edit mod
|
||||||
* @return string
|
* @return string
|
||||||
@ -83,12 +144,70 @@ class FormSetup
|
|||||||
if ($reshook > 0) {
|
if ($reshook > 0) {
|
||||||
return $hookmanager->resPrint;
|
return $hookmanager->resPrint;
|
||||||
} else {
|
} else {
|
||||||
$out = '<input type="hidden" name="token" value="' . newToken() . '">';
|
$out = '<!-- Start generateOutput from FormSetup class -->';
|
||||||
|
$out.= $this->htmlBeforeOutputForm;
|
||||||
|
|
||||||
if ($editMode) {
|
if ($editMode) {
|
||||||
$out .= '<input type="hidden" name="action" value="update">';
|
$out.= '<form ' . self::generateAttributesStringFromArray($this->formAttributes) . ' >';
|
||||||
|
|
||||||
|
// generate hidden values from $this->formHiddenInputs
|
||||||
|
if (!empty($this->formHiddenInputs) && is_array($this->formHiddenInputs)) {
|
||||||
|
foreach ($this->formHiddenInputs as $hiddenKey => $hiddenValue) {
|
||||||
|
$out.= '<input type="hidden" name="'.dol_escape_htmltag($hiddenKey).'" value="' . dol_escape_htmltag($hiddenValue) . '">';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$out .= '<table class="noborder centpercent">';
|
// generate output table
|
||||||
|
$out .= $this->generateTableOutput($editMode);
|
||||||
|
|
||||||
|
|
||||||
|
$reshook = $hookmanager->executeHooks('formSetupBeforeGenerateOutputButton', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
||||||
|
if ($reshook < 0) {
|
||||||
|
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reshook > 0) {
|
||||||
|
return $hookmanager->resPrint;
|
||||||
|
} elseif ($editMode) {
|
||||||
|
$out .= '<br>'; // Todo : remove this <br/> by adding style to form-setup-button-container css class in all themes
|
||||||
|
$out .= '<div class="form-setup-button-container center">'; // Todo : remove .center by adding style to form-setup-button-container css class in all themes
|
||||||
|
$out.= $this->htmlOutputMoreButton;
|
||||||
|
$out .= '<input class="button button-save" type="submit" value="' . $this->langs->trans("Save") . '">'; // Todo fix dolibarr style for <button and use <button instead of input
|
||||||
|
$out .= '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($editMode) {
|
||||||
|
$out .= '</form>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$out.= $this->htmlAfterOutputForm;
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $editMode true will display output on edit mod
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function generateTableOutput($editMode = false)
|
||||||
|
{
|
||||||
|
global $hookmanager, $action;
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
||||||
|
|
||||||
|
$parameters = array(
|
||||||
|
'editMode' => $editMode
|
||||||
|
);
|
||||||
|
$reshook = $hookmanager->executeHooks('formSetupBeforeGenerateTableOutput', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
||||||
|
if ($reshook < 0) {
|
||||||
|
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reshook > 0) {
|
||||||
|
return $hookmanager->resPrint;
|
||||||
|
} else {
|
||||||
|
$out = '<table class="noborder centpercent">';
|
||||||
$out .= '<thead>';
|
$out .= '<thead>';
|
||||||
$out .= '<tr class="liste_titre">';
|
$out .= '<tr class="liste_titre">';
|
||||||
$out .= ' <td class="titlefield">' . $this->langs->trans("Parameter") . '</td>';
|
$out .= ' <td class="titlefield">' . $this->langs->trans("Parameter") . '</td>';
|
||||||
@ -247,7 +366,7 @@ class FormSetup
|
|||||||
public function exportItemsAsParamsArray()
|
public function exportItemsAsParamsArray()
|
||||||
{
|
{
|
||||||
$arrayofparameters = array();
|
$arrayofparameters = array();
|
||||||
foreach ($this->items as $key => $item) {
|
foreach ($this->items as $item) {
|
||||||
$arrayofparameters[$item->confKey] = array(
|
$arrayofparameters[$item->confKey] = array(
|
||||||
'type' => $item->getType(),
|
'type' => $item->getType(),
|
||||||
'enabled' => $item->enabled
|
'enabled' => $item->enabled
|
||||||
@ -554,7 +673,7 @@ class FormSetupItem
|
|||||||
*/
|
*/
|
||||||
public function generateInputField()
|
public function generateInputField()
|
||||||
{
|
{
|
||||||
global $conf, $user;
|
global $conf;
|
||||||
|
|
||||||
if (!empty($this->fieldOverride)) {
|
if (!empty($this->fieldOverride)) {
|
||||||
return $this->fieldOverride;
|
return $this->fieldOverride;
|
||||||
|
|||||||
@ -88,6 +88,9 @@ $arrayofparameters = array(
|
|||||||
//'MYMODULE_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
|
//'MYMODULE_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$error = 0;
|
||||||
|
$setupnotempty = 0;
|
||||||
|
|
||||||
// Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
|
// Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
|
||||||
$useFormSetup = 0;
|
$useFormSetup = 0;
|
||||||
// Convert arrayofparameter into a formSetup object
|
// Convert arrayofparameter into a formSetup object
|
||||||
@ -95,35 +98,44 @@ if (!empty($arrayofparameters) && $useFormSetup && (float) DOL_VERSION >= 15) {
|
|||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
|
||||||
$formSetup = new FormSetup($db);
|
$formSetup = new FormSetup($db);
|
||||||
|
|
||||||
foreach ($arrayofparameters as $key => $val) {
|
// you can use the param convertor
|
||||||
if ($val['enabled']) {
|
$formSetup->addItemsFromParamsArray($arrayofparameters);
|
||||||
$item = $formSetup->newItem($key);
|
|
||||||
|
|
||||||
if ($val['type'] == 'string') {
|
// or use the new system see exemple as follow (or use both because you can ;-) )
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Hôte
|
||||||
|
$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 = $val['css'];
|
$item->cssClass = 'minwidth500';
|
||||||
}
|
|
||||||
if ($val['type'] == 'thirdparty_type') {
|
// 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
|
||||||
|
$item = $formSetup->newItem('MYMODULE_MYPARAM2');
|
||||||
|
$item->nameText = $item->getNameText().' more html text ';
|
||||||
|
|
||||||
|
// Setup conf MYMODULE_MYPARAM3
|
||||||
|
$item = $formSetup->newItem('MYMODULE_MYPARAM3');
|
||||||
$item->setAsThirdpartyType();
|
$item->setAsThirdpartyType();
|
||||||
}
|
|
||||||
if ($val['type'] == 'yesno') {
|
// Setup conf MYMODULE_MYPARAM4 : exemple of quick define write style
|
||||||
$formSetup->newItem($key)->setAsYesNo();
|
$formSetup->newItem('MYMODULE_MYPARAM4')->setAsYesNo();
|
||||||
}
|
|
||||||
if ($val['type'] == 'emailtemplate:thirdparty') {
|
// Setup conf MYMODULE_MYPARAM5
|
||||||
$formSetup->newItem($key)->setAsEmailTemplate('thirdparty');
|
$formSetup->newItem('MYMODULE_MYPARAM5')->setAsEmailTemplate('thirdparty');
|
||||||
}
|
|
||||||
if ($val['type'] == 'securekey') {
|
// Setup conf MYMODULE_MYPARAM6
|
||||||
$formSetup->newItem($key)->setAsSecureKey()->enabled = 0; // disabled
|
$formSetup->newItem('MYMODULE_MYPARAM6')->setAsSecureKey()->enabled = 0; // disabled
|
||||||
}
|
|
||||||
if ($val['type'] == 'product') {
|
// Setup conf MYMODULE_MYPARAM7
|
||||||
$formSetup->newItem($key)->setAsProduct();
|
$formSetup->newItem('MYMODULE_MYPARAM7')->setAsProduct();
|
||||||
}
|
*/
|
||||||
}
|
|
||||||
}
|
$setupnotempty = count($formSetup->items);
|
||||||
}
|
}
|
||||||
|
|
||||||
$error = 0;
|
|
||||||
$setupnotempty = 0;
|
|
||||||
|
|
||||||
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
|
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
|
||||||
|
|
||||||
@ -258,13 +270,13 @@ echo '<span class="opacitymedium">'.$langs->trans("MyModuleSetupPage").'</span><
|
|||||||
|
|
||||||
|
|
||||||
if ($action == 'edit') {
|
if ($action == 'edit') {
|
||||||
|
if ($useFormSetup && (float) DOL_VERSION >= 15) {
|
||||||
|
print $formSetup->generateOutput(true);
|
||||||
|
} else {
|
||||||
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||||
print '<input type="hidden" name="action" value="update">';
|
print '<input type="hidden" name="action" value="update">';
|
||||||
|
|
||||||
if ($useFormSetup && (float) DOL_VERSION >= 15) {
|
|
||||||
print $formSetup->generateOutput(true);
|
|
||||||
} else {
|
|
||||||
print '<table class="noborder centpercent">';
|
print '<table class="noborder centpercent">';
|
||||||
print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
||||||
|
|
||||||
@ -350,18 +362,19 @@ if ($action == 'edit') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
print '</table>';
|
print '</table>';
|
||||||
}
|
|
||||||
print '<br><div class="center">';
|
print '<br><div class="center">';
|
||||||
print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
|
print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
|
|
||||||
print '</form>';
|
print '</form>';
|
||||||
|
}
|
||||||
|
|
||||||
print '<br>';
|
print '<br>';
|
||||||
} else {
|
} else {
|
||||||
if ($useFormSetup && (float) DOL_VERSION >= 15) {
|
if ($useFormSetup && (float) DOL_VERSION >= 15) {
|
||||||
if (!empty($formSetup->items)) {
|
if (!empty($formSetup->items)) {
|
||||||
print $formSetup->generateOutput();
|
print $formSetup->generateOutput();
|
||||||
$setupnotempty = count($formSetup->items);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!empty($arrayofparameters)) {
|
if (!empty($arrayofparameters)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user