Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/Db/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/Db/QuestionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Loading