Skip to content

Commit

Permalink
MDL-69657 h5p: add component to the embed H5P code
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sarjona authored and ericmerrill committed Sep 8, 2020
1 parent 535523f commit 874bdf2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions h5p/classes/player.php
Expand Up @@ -440,19 +440,26 @@ private function get_embed_code(string $url, bool $embedenabled): string {
}

$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);
}

/**
* 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);
}

/**
Expand Down

0 comments on commit 874bdf2

Please sign in to comment.