diff --git a/lib/completionlib.php b/lib/completionlib.php index e72de6ed75d..451cd8a4bc6 100644 --- a/lib/completionlib.php +++ b/lib/completionlib.php @@ -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; diff --git a/lib/modinfolib.php b/lib/modinfolib.php index 02fe0b5f4ac..0949413b499 100644 --- a/lib/modinfolib.php +++ b/lib/modinfolib.php @@ -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() { diff --git a/mod/folder/lib.php b/mod/folder/lib.php index c450915cb1d..2fe3f23e0f6 100644 --- a/mod/folder/lib.php +++ b/mod/folder/lib.php @@ -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(); }