protected function validate_draft_files() {
        global $USER;
        $mform =& $this->_form;

        $errors = array();
        //Go through all the required elements and make sure you hit filepicker or
        //filemanager element.
        foreach ($mform->_rules as $elementname => $rules) {
            $elementtype = $mform->getElementType($elementname);
            //If element is of type filepicker then do validation
            if (($elementtype == 'filepicker') || ($elementtype == 'filemanager')){
                //Check if rule defined is required rule
                foreach ($rules as $rule) {
                    if ($rule['type'] == 'required') {
                        $draftid = (int)$mform->getSubmitValue($elementname);
                        $fs = get_file_storage();
                        $context = context_user::instance($USER->id);
                        if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
                            $errors[$elementname] = $rule['message'];
                        }
                    }
                }
            }
        }
        // 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 {
            return $errors;
        }
    }
protected function validate_draft_files() {
        global $USER;
        $mform =& $this->_form;

        $errors = array();
        //Go through all the required elements and make sure you hit filepicker or
        //filemanager element.
        foreach ($mform->_rules as $elementname => $rules) {
            $elementtype = $mform->getElementType($elementname);
            //If element is of type filepicker then do validation
            if (($elementtype == 'filepicker') || ($elementtype == 'filemanager')){
                //Check if rule defined is required rule
                foreach ($rules as $rule) {
                    if ($rule['type'] == 'required') {
                        $draftid = (int)$mform->getSubmitValue($elementname);
                        $fs = get_file_storage();
                        $context = context_user::instance($USER->id);
                        if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
                            $errors[$elementname] = $rule['message'];
                        }
                    }
                }
            }
        }
        // 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 {
            return $errors;
        }
    }
protected function validate_draft_files ( ) { global $ USER ; $ mform = & $ this -> _form ; $ errors = array ( ) ; //Go through all the required elements and make sure you hit filepicker or //filemanager element. foreach ( $ mform -> _rules as $ elementname => $ rules ) { $ elementtype = $ mform -> getElementType ( $ elementname ) ; //If element is of type filepicker then do validation if ( ( $ elementtype == 'filepicker' ) || ( $ elementtype == 'filemanager' ) ) { //Check if rule defined is required rule foreach ( $ rules as $ rule ) { if ( $ rule [ 'type' ] == 'required' ) { $ draftid = ( int ) $ mform -> getSubmitValue ( $ elementname ) ; $ fs = get_file_storage ( ) ; $ context = context_user :: instance ( $ USER -> id ) ; if ( ! $ files = $ fs -> get_area_files ( $ context -> id , 'user' , 'draft' , $ draftid , 'id DESC' , false ) ) { $ errors [ $ elementname ] = $ rule [ 'message' ] ; } } } } } // 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 { return $ errors ; } }
Internal method. Validates filepicker and filemanager files if they are
set as required fields. Also, sets the error message if encountered one.

@return bool|array with errors
Internal method . Validates filepicker and filemanager files if they are set as required fields . Also sets the error message if encountered one .