MDL-57898 customfield: Set the handler's parent context in course_create
authorJun Pataleta <jun@moodle.com>
Mon, 21 Jan 2019 07:45:12 +0000 (15:45 +0800)
committerJun Pataleta <jun@moodle.com>
Mon, 21 Jan 2019 07:46:33 +0000 (15:46 +0800)
course/lib.php

index da2524a..55cc640 100644 (file)
@@ -2490,6 +2490,10 @@ function create_course($data, $editoroptions = NULL) {
 
     // Save custom fields if there are any of them in the form.
     $handler = core_course\customfield\course_handler::create();
+    // Make sure to set the handler's parent context first.
+    $coursecatcontext = context_coursecat::instance($category->id);
+    $handler->set_parent_context($coursecatcontext);
+    // Save the custom field data.
     $data->id = $course->id;
     $handler->instance_form_save($data, true);