-
Bug
-
Resolution: Fixed
-
Minor
-
3.5.7, 3.6.5, 3.7.1, 3.8
-
MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE
-
MOODLE_36_STABLE, MOODLE_37_STABLE
-
MDL-66409-edit-numerical/master -
When editing a numerical question in a lesson, all the answers equal to zero are being deleted.
This has been fixed when adding such an answer (MDL-57366) but editing is still broken.
The field text value is saved into a lesson_page_answer (extending lesson_base) object. And within that class, the isset function is overridden and is returning the empty function result.
Which makes this test https://github.com/moodle/moodle/blob/MOODLE_36_STABLE/mod/lesson/locallib.php#L4479 fail. The answer is therefore dropped.
A simple fix would be to replace the test mentioned above:
if (isset($this->answers[$i]->answer) && $this->answers[$i]->answer != '') { |
with
if ($this->answers[$i]->answer !== null && $this->answers[$i]->answer !== '') { |
to avoid calling the "magic" isset function.
In order to reproduce the issue:
- Create a new lesson
- Add a new numerical page
- Add an answer with value of 0
- Save the question
- Edit that question and save it again
=> The answer is dropped.