MDL-71096 core: Add meta information about APIs to core
[moodle.git] / enrol / editinstance_form.php
blob53ab92f011afc60180ed51d824ceae182093d6a2
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * Adds new instance of enrol_plugin to specified course or edits current instance.
20 * @package core_enrol
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');
29 /**
30 * Standard edit form shared by all enrol plugins.
32 * @package core_enrol
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 {
38 /**
39 * Called to define this moodle form
41 * @return void
43 public function definition() {
44 global $DB;
46 $mform = $this->_form;
48 list($instance, $plugin, $context, $type, $returnurl) = $this->_customdata;
50 $mform->addElement('header', 'header', get_string('pluginname', 'enrol_' . $type));
52 $plugin->edit_instance_form($instance, $mform, $context);
54 $mform->addElement('hidden', 'id');
55 $mform->setType('id', PARAM_INT);
56 $mform->addElement('hidden', 'courseid');
57 $mform->setType('courseid', PARAM_INT);
59 $mform->addElement('hidden', 'type');
60 $mform->setType('type', PARAM_COMPONENT);
61 $instance->type = $type;
63 $mform->addElement('hidden', 'returnurl');
64 $mform->setType('returnurl', PARAM_LOCALURL);
65 $mform->setConstant('returnurl', $returnurl);
67 $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
69 $this->set_data($instance);
72 /**
73 * Validate this form. Calls plugin validation method.
75 * @param array $data
76 * @param array $files
77 * @return array
79 public function validation($data, $files) {
80 $errors = parent::validation($data, $files);
82 list($instance, $plugin, $context, $type) = $this->_customdata;
84 $pluginerrors = $plugin->edit_instance_validation($data, $files, $instance, $context);
86 $errors = array_merge($errors, $pluginerrors);
88 return $errors;