Skip to content
Browse files

MDL-33927 Filemanager - enforce the maxfiles limit on form submission

  • Loading branch information...
1 parent 2cbdaa7 commit a32dabc26038861aa6f065a65b0e73a1064cbe86 @davosmith davosmith committed Jul 9, 2012
Showing with 17 additions and 0 deletions.
  1. +1 −0 lang/en/form.php
  2. +16 −0 lib/formslib.php
View
1 lang/en/form.php
@@ -30,6 +30,7 @@
$string['err_alphanumeric'] = 'You must enter only letters or numbers here.';
$string['err_email'] = 'You must enter a valid email address here.';
$string['err_lettersonly'] = 'You must enter only letters here.';
+$string['err_maxfiles'] = 'You must not attach more than {$a} files here.';
$string['err_maxlength'] = 'You must enter not more than {$a->format} characters here.';
$string['err_minlength'] = 'You must enter at least {$a->format} characters here.';
$string['err_nonzero'] = 'You must enter a number not starting with a 0 here.';
View
16 lib/formslib.php
@@ -385,6 +385,22 @@ protected function validate_draft_files() {
}
}
}
+ // Check all the filemanager elements to make sure they do not have too many
+ // files in them.
+ foreach ($mform->_elements as $element) {
+ if ($element->_type == 'filemanager') {
+ $maxfiles = $element->getMaxfiles();
+ if ($maxfiles > 0) {
+ $draftid = (int)$element->getValue();
+ $fs = get_file_storage();
+ $context = context_user::instance($USER->id);
+ $files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, '', false);
+ if (count($files) > $maxfiles) {
+ $errors[$element->getName()] = get_string('err_maxfiles', 'form', $maxfiles);
+ }
+ }
+ }
+ }
if (empty($errors)) {
return true;
} else {

0 comments on commit a32dabc

Please sign in to comment.
Something went wrong with that request. Please try again.