MDL-36710 calendar: Implementing proper required rules for filepicker
This commit is contained in:
@@ -105,19 +105,30 @@ class calendar_addsubscription_form extends moodleform {
|
||||
* @return array
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
global $USER;
|
||||
|
||||
$errors = parent::validation($data, $files);
|
||||
|
||||
if (empty($data['url']) && empty($data['importfile'])) {
|
||||
if (!empty($data['importfrom']) && $data['importfrom'] == CALENDAR_IMPORT_FROM_FILE) {
|
||||
if ($data['importfrom'] == CALENDAR_IMPORT_FROM_FILE) {
|
||||
if (empty($data['importfile'])) {
|
||||
$errors['importfile'] = get_string('errorrequiredurlorfile', 'calendar');
|
||||
} else {
|
||||
$errors['url'] = get_string('errorrequiredurlorfile', 'calendar');
|
||||
}
|
||||
} else if (!empty($data['url'])) {
|
||||
if (clean_param($data['url'], PARAM_URL) !== $data['url']) {
|
||||
$errors['url'] = get_string('invalidurl', 'error');
|
||||
// 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_param($data['url'], PARAM_URL) !== $data['url'])) {
|
||||
$errors['url'] = get_string('invalidurl', 'error');
|
||||
} else {
|
||||
// Shouldn't happen.
|
||||
$errors['url'] = get_string('errorrequiredurlorfile', 'calendar');
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user