2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Adds new instance of enrol_plugin to specified course or edits current instance.
21 * @copyright 2015 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
27 require_once($CFG->libdir
.'/formslib.php');
30 * Standard edit form shared by all enrol plugins.
33 * @copyright 2015 Damyon Wiese
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class enrol_instance_edit_form
extends moodleform
{
39 * Called to define this moodle form
43 public function definition() {
46 $mform = $this->_form
;
48 list($instance, $plugin, $context, $type, $returnurl) = $this->_customdata
;
50 $plugin->edit_instance_form($instance, $mform, $context);
52 $mform->addElement('hidden', 'id');
53 $mform->setType('id', PARAM_INT
);
54 $mform->addElement('hidden', 'courseid');
55 $mform->setType('courseid', PARAM_INT
);
57 $mform->addElement('hidden', 'type');
58 $mform->setType('type', PARAM_COMPONENT
);
59 $instance->type
= $type;
61 $mform->addElement('hidden', 'returnurl');
62 $mform->setType('returnurl', PARAM_LOCALURL
);
63 $mform->setConstant('returnurl', $returnurl);
65 $this->add_action_buttons(true, ($instance->id ?
null : get_string('addinstance', 'enrol')));
67 $this->set_data($instance);
71 * Validate this form. Calls plugin validation method.
77 public function validation($data, $files) {
78 $errors = parent
::validation($data, $files);
80 list($instance, $plugin, $context, $type) = $this->_customdata
;
82 $pluginerrors = $plugin->edit_instance_validation($data, $files, $instance, $context);
84 $errors = array_merge($errors, $pluginerrors);