From 330ba8cb10bb28387a74a168c742d5ac1575c7f2 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Wed, 19 Aug 2020 08:52:36 +0200 Subject: [PATCH] MDL-69174 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. --- h5p/classes/player.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/h5p/classes/player.php b/h5p/classes/player.php index 9cbc12107bf..a94d9b1e06a 100644 --- a/h5p/classes/player.php +++ b/h5p/classes/player.php @@ -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); } /** -- 2.43.0