. /** * Upload files to content bank form * * @package core_contentbank * @copyright 2020 Amaia Anabitarte * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); require_once("$CFG->libdir/formslib.php"); /** * Class contentbank_files_form * * @package core_contentbank * @copyright 2020 Amaia Anabitarte * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class contentbank_files_form extends moodleform { /** * Add elements to this form. */ public function definition() { $mform = $this->_form; $mform->addElement('hidden', 'contextid', $this->_customdata['contextid']); $mform->setType('contextid', PARAM_INT); $options = $this->_customdata['options']; $mform->addElement('filepicker', 'file', get_string('file', 'core_contentbank'), null, $options); $mform->addHelpButton('file', 'file', 'core_contentbank'); $mform->addRule('file', null, 'required'); $this->add_action_buttons(true, get_string('savechanges')); $data = $this->_customdata['data']; $this->set_data($data); } /** * Validate incoming data. * * @param array $data * @param array $files * @return array */ public function validation($data, $files) { $errors = array(); $draftitemid = $data['file']; if (file_is_draft_area_limit_reached($draftitemid, $this->_customdata['options']['areamaxbytes'])) { $errors['file'] = get_string('userquotalimit', 'error'); } return $errors; } }