diff --git a/classes/components/forms/FormComponent.php b/classes/components/forms/FormComponent.php index 4d453e1f49a..3263ec6f8f2 100644 --- a/classes/components/forms/FormComponent.php +++ b/classes/components/forms/FormComponent.php @@ -335,7 +335,7 @@ public function getFieldConfig($field) $config['value'] = $field->isMultilingual ? [] : $field->getEmptyValue(); } if ($field->isMultilingual) { - if (is_null($config['value'])) { + if (!is_array($config['value'])) { $config['value'] = []; } foreach ($this->locales as $locale) { diff --git a/classes/plugins/ThemePlugin.php b/classes/plugins/ThemePlugin.php index bb51d1fb7ed..f2d8a39992c 100644 --- a/classes/plugins/ThemePlugin.php +++ b/classes/plugins/ThemePlugin.php @@ -569,7 +569,7 @@ public function getOptionValues($contextId) foreach ($this->options as $optionName => $optionConfig) { $value = $values[$optionName] ?? null; // Convert values stored in the db to the type of the default value - if (!is_null($optionConfig->default)) { + if ($value !== null && $optionConfig->default !== null) { switch (gettype($optionConfig->default)) { case 'boolean': $value = !$value || $value === 'false' ? false : true; @@ -579,7 +579,7 @@ public function getOptionValues($contextId) break; case 'array': try { - $value = json_decode($value, true, flags: JSON_THROW_ON_ERROR); + $value = json_decode((string) $value, true, flags: JSON_THROW_ON_ERROR); } catch (Exception) { // FIXME: pkp/pkp-lib#6250 Remove after 3.3.x upgrade code is removed (see also pkp/pkp-lib#5772) $value = unserialize($value); @@ -588,6 +588,16 @@ public function getOptionValues($contextId) break; } } + // If the value isn't null and it's a multilingual field, then we must ensure it's an array + if ($optionConfig->isMultilingual && $value !== null && !is_array($value)) { + try { + $value = json_decode((string) $value, true, flags: JSON_THROW_ON_ERROR); + } catch (Exception) { + // FIXME: pkp/pkp-lib#6250 Remove after 3.3.x upgrade code is removed (see also pkp/pkp-lib#5772) + $value = unserialize($value); + } + $value = is_array($value) ? $value : []; + } $return[$optionName] = $value; }