fix: [settings] Make sure to save multi-select value as an array
parent
ab7db2c348
commit
6c4efc044d
|
@ -56,6 +56,13 @@ class SettingsTable extends AppTable
|
|||
$errors[] = __('Invalid option provided');
|
||||
}
|
||||
}
|
||||
if ($setting['type'] == 'multi-select') {
|
||||
foreach ($value as $v) {
|
||||
if (!in_array($v, array_keys($setting['options']))) {
|
||||
$errors[] = __('Invalid option provided');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($errors) && !empty($setting['beforeSave'])) {
|
||||
$setting['value'] = $value ?? '';
|
||||
$beforeSaveResult = $this->SettingsProvider->evaluateFunctionForSetting($setting['beforeSave'], $setting);
|
||||
|
@ -79,6 +86,11 @@ class SettingsTable extends AppTable
|
|||
if ($setting['type'] == 'boolean') {
|
||||
return (bool) $value;
|
||||
}
|
||||
if ($setting['type'] == 'multi-select') {
|
||||
if (!is_array($value)) {
|
||||
$value = json_decode($value);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,13 @@
|
|||
$settingId = str_replace('.', '_', $settingName);
|
||||
$setting['value'] = $setting['value'] ?? '';
|
||||
if ($setting['type'] == 'multi-select') {
|
||||
$setting['value'] = json_decode(($setting['value']));
|
||||
if (!is_array($setting['value'])) {
|
||||
$firstChar = substr($setting['value'], 0, 1);
|
||||
if ($firstChar != '{' && $firstChar != '[') { // make sure to cast a simple string into an array
|
||||
$setting['value'] = sprintf('["%s"]', $setting['value']);
|
||||
}
|
||||
$setting['value'] = json_decode($setting['value']);
|
||||
}
|
||||
}
|
||||
$options = [];
|
||||
$options[] = $appView->Bootstrap->genNode('option', ['value' => '-1', 'data-is-empty-option' => '1'], __('Select an option'));
|
||||
|
|
Loading…
Reference in New Issue