-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
4.2.7, 4.3
-
None
-
MOODLE_402_STABLE, MOODLE_403_STABLE
The repository documentation says in https://moodledev.io/docs/apis/plugintypes/repository#course-and-user-repository-instances:
The plugin must provide a get_instance_option_names method which returns at least one instance option name.
And in https://moodledev.io/docs/apis/plugintypes/repository#get_instance_option_names-array
Optional. Return an array of strings. These strings are setting names. These settings are specific to an instance.
If the function returns an empty array, the API will consider that the plugin displays only one repository in the file picker.
I cannot find anything mentioning that the array has to contain a `sortorder` element, but if `get_instance_option_names` does not return `sortorder` and the error reporting is strict the code throws a warning:
Moodle exception: Exception - Warning: Undefined array key "sortorder" in [dirroot]/repository/lib.php on line 1952 URL: https://apache/blog/edit.php?action=add&userid=2 Debug info: Error code: generalexceptionmessage Stack trace: * line 157 of /lib/behat/lib.php: Exception thrown * line 1952 of /repository/lib.php: call to behat_error_handler() * line 152 of /repository/ocis/lib.php: call to repository->get_meta() * line 102 of /repository/repository_ajax.php: call to repository_ocis->get_listing()
Exception - Warning: Undefined array key "sortorder" in [dirroot]/repository/lib.php on line 1952 (Exception)
The problem is the line `$meta->sortorder = $this->options['sortorder'];`
Please note: this is most likely not a problem on production systems, but is currently for us when we try to run tests with strict error reporting.
Workarounds:
- reduce error reporting
- add `sortorder` to the array returned by 'get_instance_option_names'
I'm happy to make a fix, but I don't know if this is an issue in the docs or in the code?
e.g. a simple check with `array_key_exists()` would fix the problem.