MDL-69657 h5p: add component to the embed H5P code

When the Moodle component is passed to the player, xAPI tracking
is enabled so, if the component implements required xAPI API methods
(for instance, mod_h5pactivity does), grades and responses are sent.
Adding this component to the embed code will help to add
the embed code from a mod_h5pactivity to any other place (such as label,
page or book), and being able to track the responses to the original
mod_h5pactivity.

Backport from MDL-69174
This commit is contained in:
Sara Arjona
2020-09-08 13:08:13 -04:00
committed by Eric Merrill
parent 535523f21f
commit 874bdf2035
+10 -3
View File
@@ -440,7 +440,7 @@ class player {
}
$template = new \stdClass();
$template->embedurl = self::get_embed_url($url)->out();
$template->embedurl = self::get_embed_url($url, $this->component)->out(false);
return $OUTPUT->render_from_template('core_h5p/h5pembed', $template);
}
@@ -448,11 +448,18 @@ class player {
/**
* Get the encoded URL for embeding this H5P content.
* @param string $url The URL of the .h5p file.
* @param string $component optional Moodle component to send xAPI tracking
*
* @return \moodle_url The embed URL.
*/
public static function get_embed_url(string $url): \moodle_url {
return new \moodle_url('/h5p/embed.php', ['url' => $url]);
public static function get_embed_url(string $url, string $component = ''): \moodle_url {
$params = ['url' => $url];
if (!empty($component)) {
// If component is not empty, it will be passed too, in order to allow tracking too.
$params['component'] = $component;
}
return new \moodle_url('/h5p/embed.php', $params);
}
/**