Skip to content

fix: question edit form #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2025
Merged
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
15 changes: 12 additions & 3 deletions edit_questionpy_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,18 @@ public function set_data($question): void {

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

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

parent::set_data($question);
}
Expand Down