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:
parent
ce5b93c5c6
commit
18cbc156dc
1 changed files with 29 additions and 5 deletions
32
lib.php
32
lib.php
|
@ -51,6 +51,27 @@ function mod_exp360_cm_info_dynamic(cm_info $cm)
|
||||||
return;
|
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');
|
$renderer = $PAGE->get_renderer('mod_exp360');
|
||||||
$modals = $renderer->render_modals();
|
$modals = $renderer->render_modals();
|
||||||
$script = $renderer->render_activity($cm->id, $cm->get_formatted_name());
|
$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);
|
$cm->set_content($modals . $script);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mod_exp360_supports($feature) {
|
function mod_exp360_supports($feature)
|
||||||
switch($feature) {
|
{
|
||||||
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
|
switch ($feature) {
|
||||||
default: return null;
|
case FEATURE_COMPLETION_TRACKS_VIEWS:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue