public function validation($data, $files) {
        global $USER;

        $errors = parent::validation($data, $files);

        $eventtype = isset($data['eventtype']) ? $data['eventtype'] : null;
        $coursekey = ($eventtype == 'group') ? 'groupcourseid' : 'courseid';
        $courseid = (!empty($data[$coursekey])) ? $data[$coursekey] : null;
        $eventtypes = calendar_get_allowed_event_types($courseid);

        if (empty($eventtype) || !isset($eventtypes[$eventtype])) {
            $errors['eventtype'] = get_string('invalideventtype', 'calendar');
        }

        if ($data['importfrom'] == CALENDAR_IMPORT_FROM_FILE) {
            if (empty($data['importfile'])) {
                $errors['importfile'] = get_string('errorrequiredurlorfile', 'calendar');
            } else {
                // Make sure the file area is not empty and contains only one file.
                $draftitemid = $data['importfile'];
                $fs = get_file_storage();
                $usercontext = \context_user::instance($USER->id);
                $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false);
                if (count($files) !== 1) {
                    $errors['importfile'] = get_string('errorrequiredurlorfile', 'calendar');
                }
            }
        } else if (($data['importfrom'] == CALENDAR_IMPORT_FROM_URL)) {
            // Clean input calendar url.
            $url = clean_param($data['url'], PARAM_URL);
            if (empty($url) || ($url !== $data['url'])) {
                $errors['url']  = get_string('invalidurl', 'error');
            }
        } else {
            // Shouldn't happen.
            $errors['url'] = get_string('errorrequiredurlorfile', 'calendar');
        }

        return $errors;
    }