diff --git a/enrol/editinstance.php b/enrol/editinstance.php index 38d3ae7750820..12cea2e39c3f0 100644 --- a/enrol/editinstance.php +++ b/enrol/editinstance.php @@ -28,7 +28,7 @@ $courseid = required_param('courseid', PARAM_INT); $type = required_param('type', PARAM_COMPONENT); $instanceid = optional_param('id', 0, PARAM_INT); - +$return = optional_param('returnurl', 0, PARAM_LOCALURL); $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); $context = context_course::instance($course->id, MUST_EXIST); @@ -43,7 +43,10 @@ $PAGE->set_url('/enrol/editinstance.php', array('courseid' => $course->id, 'id' => $instanceid, 'type' => $type)); $PAGE->set_pagelayout('admin'); -$return = new moodle_url('/enrol/instances.php', array('id' => $course->id)); +if (empty($return)) { + $return = new moodle_url('/enrol/instances.php', array('id' => $course->id)); +} + if (!enrol_is_enabled($type)) { redirect($return); } @@ -62,7 +65,7 @@ $instance->status = ENROL_INSTANCE_ENABLED; // Do not use default for automatically created instances here. } -$mform = new enrol_instance_edit_form(null, array($instance, $plugin, $context, $type)); +$mform = new enrol_instance_edit_form(null, array($instance, $plugin, $context, $type, $return)); if ($mform->is_cancelled()) { redirect($return); diff --git a/enrol/editinstance_form.php b/enrol/editinstance_form.php index 728a7e8926db1..53ab92f011afc 100644 --- a/enrol/editinstance_form.php +++ b/enrol/editinstance_form.php @@ -45,7 +45,7 @@ public function definition() { $mform = $this->_form; - list($instance, $plugin, $context, $type) = $this->_customdata; + list($instance, $plugin, $context, $type, $returnurl) = $this->_customdata; $mform->addElement('header', 'header', get_string('pluginname', 'enrol_' . $type)); @@ -60,6 +60,10 @@ public function definition() { $mform->setType('type', PARAM_COMPONENT); $instance->type = $type; + $mform->addElement('hidden', 'returnurl'); + $mform->setType('returnurl', PARAM_LOCALURL); + $mform->setConstant('returnurl', $returnurl); + $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol'))); $this->set_data($instance);