mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 22:15:24 +02:00
MDL-71410 core: Prevent recursively calling getters
This commit is contained in:
parent
796e82124f
commit
4ddc9fe0f4
@ -1117,7 +1117,9 @@ class completion_info {
|
||||
// Custom activity module completion data.
|
||||
|
||||
// Cast custom data to array before checking for custom completion rules.
|
||||
$customdata = (array)$cm->customdata;
|
||||
// We call ->get_custom_data() instead of ->customdata here because there is the chance of recursive calling,
|
||||
// and we cannot call a getter from a getter in PHP.
|
||||
$customdata = (array) $cm->get_custom_data();
|
||||
// Return early if the plugin does not define custom completion rules.
|
||||
if (empty($customdata['customcompletionrules'])) {
|
||||
return $data;
|
||||
|
@ -1420,9 +1420,14 @@ class cm_info implements IteratorAggregate {
|
||||
return $this->onclick;
|
||||
}
|
||||
/**
|
||||
* Getter method for property $customdata, ensures that dynamic data is retrieved.
|
||||
*
|
||||
* This method is normally called by the property ->customdata, but can be called directly if there
|
||||
* is a case when it might be called recursively (you can't call property values recursively).
|
||||
*
|
||||
* @return mixed Optional custom data stored in modinfo cache for this activity, or null if none
|
||||
*/
|
||||
private function get_custom_data() {
|
||||
public function get_custom_data() {
|
||||
$this->obtain_dynamic_data();
|
||||
return $this->customdata;
|
||||
}
|
||||
@ -1688,6 +1693,9 @@ class cm_info implements IteratorAggregate {
|
||||
* @param mixed $value The value
|
||||
*/
|
||||
public function override_customdata($name, $value) {
|
||||
if (!is_array($this->customdata)) {
|
||||
$this->customdata = [];
|
||||
}
|
||||
$this->customdata[$name] = $value;
|
||||
}
|
||||
|
||||
@ -1893,7 +1901,8 @@ class cm_info implements IteratorAggregate {
|
||||
* the module or not.
|
||||
*
|
||||
* As part of this function, the module's _cm_info_dynamic function from its lib.php will
|
||||
* be called (if it exists).
|
||||
* be called (if it exists). Make sure that the functions that are called here do not use
|
||||
* any getter magic method from cm_info.
|
||||
* @return void
|
||||
*/
|
||||
private function obtain_dynamic_data() {
|
||||
|
@ -439,7 +439,7 @@ function folder_get_coursemodule_info($cm) {
|
||||
* @param cm_info $cm
|
||||
*/
|
||||
function folder_cm_info_dynamic(cm_info $cm) {
|
||||
if ($cm->customdata) {
|
||||
if ($cm->get_custom_data()) {
|
||||
// the field 'customdata' is not empty IF AND ONLY IF we display contens inline
|
||||
$cm->set_no_view_link();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user