From 2f61fe976cfbd37e4c49d5803b7c0cfebea0fda9 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Mon, 21 Jan 2019 15:45:12 +0800 Subject: [PATCH] MDL-57898 customfield: Set the handler's parent context in course_create --- course/lib.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/course/lib.php b/course/lib.php index da2524ab32d..55cc6409203 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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); -- 2.43.0