File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -418,9 +418,18 @@ public function set_data($question): void {
418
418
419
419
$ question ->qpy_form = $ this ->currentdata ;
420
420
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
+ }
424
433
425
434
parent ::set_data ($ question );
426
435
}
You can’t perform that action at this time.
0 commit comments