From ca795bf0be12f5e741f1711d6626a2283010acab Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Sat, 21 Nov 2026 01:56:43 +0100 Subject: [PATCH] fix(api): leave out unset extra settings when reading them Extra settings that are set back to their default, for example the lowest value of a linear scale, are stored as null, and the API returned these nulls, which its documented types do not allow. Unset values, null or false, are now left out when the extra settings are read, so this also covers questions saved earlier. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- lib/Db/Question.php | 5 ++++- tests/Unit/Db/QuestionTest.php | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Db/Question.php b/lib/Db/Question.php index 05355b95f9..e47d46c4c1 100644 --- a/lib/Db/Question.php +++ b/lib/Db/Question.php @@ -54,10 +54,13 @@ public function __construct() { } /** + * The extra settings, without the ones that are not set (false or null) + * * @return FormsQuestionExtraSettings */ public function getExtraSettings(): array { - return json_decode($this->getExtraSettingsJson() ?: '{}', true, 512, JSON_THROW_ON_ERROR); + $extraSettings = json_decode($this->getExtraSettingsJson() ?: '{}', true, 512, JSON_THROW_ON_ERROR); + return array_filter($extraSettings, static fn (mixed $value): bool => $value !== false && $value !== null); } /** diff --git a/tests/Unit/Db/QuestionTest.php b/tests/Unit/Db/QuestionTest.php index ebc58f72d5..3bebc51eb6 100644 --- a/tests/Unit/Db/QuestionTest.php +++ b/tests/Unit/Db/QuestionTest.php @@ -60,4 +60,11 @@ public function testIsEmailTypeEntity(): void { $question->setExtraSettings(['validationType' => 'text']); $this->assertFalse($question->isEmailType()); } + + public function testGetExtraSettingsLeavesOutStoredUnsetValues(): void { + $question = new Question(); + $question->setExtraSettingsJson('{"optionsLowest":null,"optionsHighest":7,"shuffleOptions":false}'); + + $this->assertSame(['optionsHighest' => 7], $question->getExtraSettings()); + } }