Skip to content

Commit faa2683

Browse files
authored
fix: question edit form
1 parent 9e71efb commit faa2683

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

edit_questionpy_form.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,18 @@ public function set_data($question): void {
418418

419419
$question->qpy_form = $this->currentdata;
420420

421-
// We do not want to populate these fields based on the stored data.
422-
$question->qpy_package_hash = $this->currentdata['qpy_package_hash'] ?? $this->currentdata['qpy_package_file_hash'] ?? '';
423-
$question->qpy_package_selected = $this->currentdata['qpy_package_selected'] ?? false;
421+
// When changing the package of a stored question, we do not want the package hash to be set in the form.
422+
// Saving the question would return us to the question edit form with the package selected.
423+
// Instead, we want to stay on the package selection page and show a "Required" message, indicating that a
424+
// package must be selected before saving a question.
425+
// The parameter `qpy_package_selected` is only present when a package was either selected or unselected.
426+
// When calling the `optional_param` method while creating or editing a question, the default value `true`
427+
// will be returned. This is not correct for the first case, but since `$question->qpy_package_hash` is not
428+
// present when creating a new question, it does not matter.
429+
$selected = $this->optional_param('qpy_package_selected', true, PARAM_BOOL);
430+
if (!$selected) {
431+
unset($question->qpy_package_hash);
432+
}
424433

425434
parent::set_data($question);
426435
}

0 commit comments

Comments
 (0)