Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-63180

filemanager throw an error if it's optional , if it uses disabledif()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Not a bug
    • Affects Version/s: 3.4.5, 3.5
    • Fix Version/s: None
    • Component/s: Files API, Forms Library
    • Labels:
      None
    • Affected Branches:
      MOODLE_34_STABLE, MOODLE_35_STABLE

      Description

      I develop a plug in (mod-simplecertificate) and after a update i get this error in my behat tests when i try to add a instance of plug in in a section:

       

      And I add a "Simple Certificate" to section "2" and I fill the form with:
        | Certificate Name | Test Simple Certificate |
        | Certificate Text | Test Simple Certificate |

       
      and the full error log is:

      Moodle exception: Exception - Argument 1 passed to file_get_all_files_in_draftarea()
      must be of the type integer, null given, called in [dirroot]/lib/form/filemanager.php on 
      line 336 More information about this error       
       ×        Debug info:        Error code: generalexceptionmessage        
       ×        Stack trace:        line 767 of /lib/filelib.php: TypeError thrown
               line 336 of /lib/form/filemanager.php: call to file_get_all_files_in_draftarea()
               line 580 of /lib/formslib.php: call to MoodleQuickForm_filemanager->validateSubmitValue()
               line 526 of /lib/formslib.php: call to moodleform->validate_defined_fields()
               line 636 of /lib/formslib.php: call to moodleform->is_validated()
               line 1095 of /course/moodleform_mod.php: call to moodleform->get_data()
               line 150 of /course/modedit.php: call to moodleform_mod->get_data()
                (Exception)
       
      

       

      In my test i use moodle_33, moodle_34 and moodle_35,  this errors  are displayed in moodle 34, but not in moodle_35,  but some users has and in travis CI reports this error. (and no erro in moodle 33)

      (php 7, 7.1, 7.2  for moodle 34 and 35), (php 5.6, 7.0, 7.1 for moodle_33)

      During my investigation i found what code is generating it.

      // Give the elements a chance to perform an implicit validation.
       $element_val = true;
       foreach ($mform->_elements as $element) {
           if (method_exists($element, 'validateSubmitValue')) {
                 $value = $mform->getSubmitValue($element->getName());
                 $result = $element->validateSubmitValue($value);
                 if (!empty($result) && is_string($result)) {
                     $element_val = false;
                     $mform->setElementError($element->getName(), $result);
                 }
            }
        }

      lib/formslib.php - lines 575 to 586

      This code only exist in moodle_34 and 35.

       

      I suspect this is because my plugin's form have 2 filemaneger (none are a required field), because the first one  when the code  $mform->getSubmitValue($element->getName())   is execute it's return a value (even if no data is set), but when the second is executed a null value is returned, which cause the error in 
      $result = $element->validateSubmitValue($value);
       
      i will attach my mod_form.php
       

        Attachments

          Activity

            People

            • Votes:
              3 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: