diff --git a/lib/Db/Question.php b/lib/Db/Question.php index 05355b95f..e47d46c4c 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 ebc58f72d..3bebc51eb 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()); + } }