Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error caused by loading assets in completion pages #533

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,18 @@ function hvp_get_core_assets($context) {
// Add core stylesheets.
foreach (\H5PCore::$styles as $style) {
$settings['core']['styles'][] = $relpath . $style . $cachebuster;
$PAGE->requires->css(new moodle_url($liburl . $style . $cachebuster));
// Only add stylesheets to page if not on a completion page.
if (!\hvp_check_completion_pages($PAGE->pagetype)) {
$PAGE->requires->css(new moodle_url($liburl . $style . $cachebuster));
}
}
// Add core JavaScript.
foreach (\H5PCore::$scripts as $script) {
$settings['core']['scripts'][] = $relpath . $script . $cachebuster;
$PAGE->requires->js(new moodle_url($liburl . $script . $cachebuster), true);
// Only add scripts to page if not on a completion page.
if (!\hvp_check_completion_pages($PAGE->pagetype)) {
$PAGE->requires->js(new moodle_url($liburl . $script . $cachebuster), true);
}
}

return $settings;
Expand Down Expand Up @@ -720,3 +726,20 @@ function hvp_create_hub_export_url($cmid, $content) {
function hvp_base64_encode($string) {
return str_replace('=', '', strtr(base64_encode($string), '+/', '-_'));
}

/**
* Check if the given page type is a completion page.
* Use this function to avoid loading H5P assets on completion pages.
*
* @param string $pageType
* @return bool
*/
function hvp_check_completion_pages($pageType) {
$completionpagetypes = [
'course-defaultcompletion' => 'Edit completion default settings (Moodle >= 4.3)',
'course-editbulkcompletion' => 'Edit completion settings in bulk for a single course',
'course-editdefaultcompletion' => 'Edit completion default settings (Moodle < 4.3)',
];

return array_key_exists($pageType, $completionpagetypes);
}