new moodle_url('/h5p/libraries.php'), ['moodle/site:config', 'moodle/h5p:updatelibraries']));
// H5P settings.
-$defaulth5plib = \core_h5p\local\library\autoloader::get_default_handler();
+$defaulth5plib = \core_h5p\local\library\autoloader::get_default_handler_library();
if (!empty($defaulth5plib)) {
// As for now this page only has this setting, it will be hidden if there isn't any H5P libraries handler defined.
$settings = new admin_settingpage('h5psettings', new lang_string('h5psettings', 'core_h5p'));
}
/**
- * Returns the default H5P library handler.
+ * Returns the default H5P library handler class.
+ *
* @return string|null H5P library handler class
*/
public static function get_default_handler(): ?string {
+ $default = null;
+ $handlers = self::get_all_handlers();
+ if (!empty($handlers)) {
+ // The default handler will be the first value in the list.
+ $default = array_shift($handlers);
+ }
+
+ return $default;
+ }
+
+ /**
+ * Returns the default H5P library handler.
+ *
+ * @return string|null H5P library handler
+ */
+ public static function get_default_handler_library(): ?string {
$default = null;
$handlers = self::get_all_handlers();
if (!empty($handlers)) {
}
}
- // If no handler has been defined or it doesn't exist, return the default one.
+ // If no handler has been defined, return the default one.
$defaulthandler = self::get_default_handler();
if (empty($defaulthandler)) {
// If there is no default handler, throw an exception.
$siteuuid2 = $this->core->get_site_uuid();
$this->assertEquals( $siteuuid, $siteuuid2);
}
+
+ /**
+ * Test if no handler has been defined.
+ */
+ public function test_get_default_handler() {
+ global $CFG;
+
+ $this->resetAfterTest(true);
+ // Emtpy the h5plibraryhandler setting.
+ $CFG->h5plibraryhandler = '';
+
+ // Get the default habdler library to use in the settings h5p page.
+ // For instance, h5plib_v124.
+ $handlerlib = autoloader::get_default_handler_library();
+ $this->assertNotNull($handlerlib);
+ $this->assertStringNotContainsString($handlerlib, '\local\library\handler');
+ // Get the default handler class.
+ // For instance, \h5plib_v124\local\library\handler.
+ $handlerclass = autoloader::get_default_handler();
+ $this->assertStringEndsWith('\local\library\handler', $handlerclass);
+ }
}