From c0bfa2fd4a2dac7dba8f781705db736c1599465a Mon Sep 17 00:00:00 2001 From: Alexander Bias Date: Wed, 20 Nov 2024 07:29:14 +0100 Subject: [PATCH] Bugfix: The starred courses popover in the navbar must only be shown if Boost Union or Boost Union child is active, resolves #759. (#762) * Bugfix: The starred courses popover in the navbar must only be shown if Boost Union or Boost Union child is active, resolves #759. * Bugfix: The starred courses popover showed a JavaScript error in the browser JS console, resolves #759 --- CHANGES.md | 2 ++ locallib.php | 26 ++++++++++++++++++++++++-- templates/popover-favourites.mustache | 1 - 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 18b21ff4eb1..a7ff2302367 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,8 @@ Changes ### Unreleased +* 2024-11-19 - Bugfix: The starred courses popover showed a JavaScript error in the browser JS console, resolves #759. +* 2024-11-19 - Bugfix: The starred courses popover in the navbar must only be shown if Boost Union or Boost Union child is active, resolves #759. * 2024-11-18 - Improvement: Add the possibility to restrict smart menus and smart menu items to site admins and non-site admins only, resolves #421. * 2024-11-18 - Bugfix: Footer displacement on pages with minimal content, resolves #655. * 2024-11-18 - Upstream change: Adopt changes from MDL-77732 ('Custom menu items do not receive active behaviour'), resolves #436 #620 #384 #715. diff --git a/locallib.php b/locallib.php index 7b15874aecb..426093e2882 100644 --- a/locallib.php +++ b/locallib.php @@ -1934,6 +1934,12 @@ function theme_boost_union_yesno_to_boolstring($var) { function theme_boost_union_get_navbar_starredcoursespopover() { global $USER, $OUTPUT; + // If a theme other than Boost Union or a child theme of it is active, return directly. + // This is necessary as the callback is called regardless of the active theme. + if (theme_boost_union_is_active_theme() != true) { + return ''; + } + // The popover is relevant only for logged-in users. If the user is not logged in, return directly. if (!isloggedin()) { return ''; @@ -2033,7 +2039,7 @@ function($favourite) { * @return string|void The legacy implementation will return a string, the hook implementation will return nothing. */ function theme_boost_union_callbackimpl_before_standard_html(&$hook = null) { - global $CFG, $PAGE; + global $CFG; // Require local library. require_once($CFG->dirroot.'/theme/boost_union/locallib.php'); @@ -2043,7 +2049,7 @@ function theme_boost_union_callbackimpl_before_standard_html(&$hook = null) { // If a theme other than Boost Union or a child theme of it is active, return directly. // This is necessary as the callback is called regardless of the active theme. - if ($PAGE->theme->name != 'boost_union' && !in_array('boost_union', $PAGE->theme->parents)) { + if (theme_boost_union_is_active_theme() != true) { if ($hook != null) { return; } else { @@ -2412,3 +2418,19 @@ function theme_boost_union_remove_hookmanipulation() { // Remove the hook overrides. $cache->delete('overrides'); } + +/** + * Helper function to check if Boost Union or a child theme of Boost Union is active. + * This is needed at multiple locations to avoid that callbacks in Boost Union affect other active themes. + * + * @return bool + */ +function theme_boost_union_is_active_theme() { + global $PAGE; + + if ($PAGE->theme->name == 'boost_union' || in_array('boost_union', $PAGE->theme->parents)) { + return true; + } else { + return false; + } +} diff --git a/templates/popover-favourites.mustache b/templates/popover-favourites.mustache index 6e13e83223d..e6b8157255f 100644 --- a/templates/popover-favourites.mustache +++ b/templates/popover-favourites.mustache @@ -60,7 +60,6 @@ require(['jquery', 'core/popover_region_controller'], function($, Controller) { var container = $('#nav-popover-favourites-container'); var controller = new Controller(container); - controller.registerEventListeners(); controller.registerListNavigationEventListeners(); }); {{/js}}