Skip to content

Commit

Permalink
Merge pull request pkp#9917 from jonasraoni/bugfix/main/6186-support-…
Browse files Browse the repository at this point in the history
…multilingual-theme-options

Bugfix/main/6186 support multilingual theme options
  • Loading branch information
jonasraoni authored Apr 26, 2024
2 parents b0c9b5f + b687fc3 commit 1b2cd55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion classes/components/forms/FormComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 12 additions & 2 deletions classes/plugins/ThemePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 1b2cd55

Please sign in to comment.