fix: prevent null PAGE error in path reflection
Added a null check for the $PAGE variable before attempting to access its protected properties via reflection. This ensures the function safely bypasses a known bug related to path handling without encountering a null reference error. Prevents potential errors during dynamic module info processing.
This commit is contained in:
parent
18cbc156dc
commit
8be9310c36
1 changed files with 17 additions and 15 deletions
32
lib.php
32
lib.php
|
@ -51,25 +51,27 @@ function mod_exp360_cm_info_dynamic(cm_info $cm)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a reflection of $PATH so we can access protected properties
|
if ($PAGE) {
|
||||||
$reflection = new ReflectionClass($PAGE);
|
// Create a reflection of $PATH so we can access protected properties
|
||||||
$urlProperty = $reflection->getProperty('_url');
|
$reflection = new ReflectionClass($PAGE);
|
||||||
$urlProperty->setAccessible(true);
|
$urlProperty = $reflection->getProperty('_url');
|
||||||
|
$urlProperty->setAccessible(true);
|
||||||
|
|
||||||
// Get the value of _url property, which is a moodle_url object
|
// Get the value of _url property, which is a moodle_url object
|
||||||
$urlObject = $urlProperty->getValue($PAGE);
|
$urlObject = $urlProperty->getValue($PAGE);
|
||||||
|
|
||||||
// Now access the path property within the moodle_url object
|
// Now access the path property within the moodle_url object
|
||||||
$urlReflection = new ReflectionClass($urlObject);
|
$urlReflection = new ReflectionClass($urlObject);
|
||||||
$pathProperty = $urlReflection->getProperty('path');
|
$pathProperty = $urlReflection->getProperty('path');
|
||||||
$pathProperty->setAccessible(true);
|
$pathProperty->setAccessible(true);
|
||||||
|
|
||||||
// Get the value of the path property
|
// Get the value of the path property
|
||||||
$pathValue = $pathProperty->getValue($urlObject);
|
$pathValue = $pathProperty->getValue($urlObject);
|
||||||
|
|
||||||
// All of this only to bypass a little bug
|
// All of this only to bypass a little bug
|
||||||
if ($pathValue == '/course/modedit.php') {
|
if ($pathValue == '/course/modedit.php') {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$renderer = $PAGE->get_renderer('mod_exp360');
|
$renderer = $PAGE->get_renderer('mod_exp360');
|
||||||
|
|
Loading…
Reference in a new issue