From 18cbc156dcdd7ca926a5cc6c9000ad9d1d563e7b Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 14 Nov 2024 16:41:34 +0100 Subject: [PATCH] fix: bypass issue with URL path in modedit.php Refactored to use reflection for accessing private URL properties to bypass a bug affecting the path property within moodle_url objects. This addresses an issue where the dynamic content rendering function prematurely exits when navigating to `modedit.php`. Improved function formatting for `mod_exp360_supports` for readability. --- lib.php | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/lib.php b/lib.php index b9971a4..0767003 100644 --- a/lib.php +++ b/lib.php @@ -51,6 +51,27 @@ function mod_exp360_cm_info_dynamic(cm_info $cm) return; } + // Create a reflection of $PATH so we can access protected properties + $reflection = new ReflectionClass($PAGE); + $urlProperty = $reflection->getProperty('_url'); + $urlProperty->setAccessible(true); + + // Get the value of _url property, which is a moodle_url object + $urlObject = $urlProperty->getValue($PAGE); + + // Now access the path property within the moodle_url object + $urlReflection = new ReflectionClass($urlObject); + $pathProperty = $urlReflection->getProperty('path'); + $pathProperty->setAccessible(true); + + // Get the value of the path property + $pathValue = $pathProperty->getValue($urlObject); + + // All of this only to bypass a little bug + if ($pathValue == '/course/modedit.php') { + return; + } + $renderer = $PAGE->get_renderer('mod_exp360'); $modals = $renderer->render_modals(); $script = $renderer->render_activity($cm->id, $cm->get_formatted_name()); @@ -59,9 +80,12 @@ function mod_exp360_cm_info_dynamic(cm_info $cm) $cm->set_content($modals . $script); } -function mod_exp360_supports($feature) { - switch($feature) { - case FEATURE_COMPLETION_TRACKS_VIEWS: return true; - default: return null; +function mod_exp360_supports($feature) +{ + switch ($feature) { + case FEATURE_COMPLETION_TRACKS_VIEWS: + return true; + default: + return null; } -} \ No newline at end of file +}