fix: [instance:settings] Normalise value before saving

pull/70/head
mokaddem 2021-07-27 10:58:34 +02:00
parent 7fc2c595d7
commit 6a89e65a37
2 changed files with 10 additions and 1 deletions

View File

@ -49,6 +49,7 @@ class SettingsTable extends AppTable
{
$errors = [];
$setting = $this->getSetting($name);
$value = $this->normaliseValue($value, $setting);
if (!empty($setting['beforeSave'])) {
$setting['value'] = $value ?? '';
$beforeSaveResult = $this->SettingsProvider->evaluateFunctionForSetting($setting['beforeSave'], $setting);
@ -67,6 +68,14 @@ class SettingsTable extends AppTable
return $errors;
}
private function normaliseValue($value, $setting)
{
if ($setting['type'] == 'boolean') {
return (bool) $value;
}
return $value;
}
private function readSettings()
{
return Configure::read()[$this::$CONFIG_KEY];

View File

@ -126,7 +126,7 @@ function isLeaf($setting)
const $input = $(this)
const $inputGroup = $(this).closest('.form-group')
const settingName = $(this).data('setting-name')
const settingValue = $(this).is(':checked')
const settingValue = $(this).is(':checked') ? 1 : 0
saveSetting($inputGroup[0], $input, settingName, settingValue)
} else {
handleSettingValueChange($(this))