From dc5cbf1532e77bb5b8cea8db4b3866d190253dbb Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 5 May 2017 14:47:27 +0800 Subject: [PATCH] MDL-50670 course: apply defaults when format was switched --- course/format/lib.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/course/format/lib.php b/course/format/lib.php index 10ccf813e1d..520f7c3aed3 100644 --- a/course/format/lib.php +++ b/course/format/lib.php @@ -678,7 +678,9 @@ abstract class format_base { if (isset($option['type'])) { $mform->setType($optionname, $option['type']); } - if (is_null($mform->getElementValue('id')) && isset($option['default'])) { + if (isset($option['default']) && !array_key_exists($optionname, $mform->_defaultValues)) { + // Set defaults for the elements in the form. + // Since we call this method after set_data() make sure that we don't override what was already set. $mform->setDefault($optionname, $option['default']); } }