#106747Site Settings of type stringlist not saved by Settings Editor
Description
*Description:*
When attempting to save site settings of type stringlist via the Settings Editor in the TYPO3 backend, the values are not stored. This occurs because the validation logic expects an array, while the input provided is a JSON-encoded string. As a result, the data is considered invalid and the save process is aborted.
- Define a site setting of type
stringlist. - Open the Settings Editor in the TYPO3 backend.
- Input a list of strings (e.g.,
["foo", "bar"]) as a JSON-encoded string. - Save the settings.
- Observe that the values are not saved.
*Expected Behavior:*
The Settings Editor should accept a valid JSON string for stringlist types, decode it, and save it as an array.
*Actual Behavior:*
The JSON-encoded string fails validation because an array is expected directly.
*Possible Fix:*
Update the validation logic to detect if the provided value is a JSON-encoded string and convert it to an array before validation. This could be implemented similar to the existing logic in the transformValue function.
public function validate(mixed $value, SettingDefinition $definition): bool
{
// Check if given value is a json-encoded string
if (is_string($value)) {
// A json-encoded stringlist only needs 2-levels
$depth = 2;
try {
$value = json_decode($value, false, 2, JSON_THROW_ON_ERROR);
} catch (\JsonException) {
return false;
}
}
if (!is_array($value)) {
return false;
}
return $this->doValidate(new StringType($this->logger), $value, $definition);
}