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.
This commit is contained in:
Kumi 2024-11-14 16:41:34 +01:00
parent ce5b93c5c6
commit 18cbc156dc
Signed by: kumi
GPG key ID: ECBCC9082395383F

34
lib.php
View file

@ -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;
}
}
}