From 14e37590bb562cb40dc1a82b21a964a74beb93e8 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Thu, 15 Apr 2021 05:27:00 +1000 Subject: [PATCH] MDL-71410 core: Introduce override_customdata() The get_custom_data() method now calls obtain_dynamic_data() because $this->customdata can be dynamic now. --- lib/modinfolib.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/modinfolib.php b/lib/modinfolib.php index b5e3d87b8ad..d0c310db9e6 100644 --- a/lib/modinfolib.php +++ b/lib/modinfolib.php @@ -701,7 +701,7 @@ class course_modinfo { * {@link cached_cm_info} * * Stage 2 - dynamic data. - * Dynamic data is user-dependend, it is stored in request-level cache. To reset this cache + * Dynamic data is user-dependent, it is stored in request-level cache. To reset this cache * {@link get_fast_modinfo()} with $reset argument may be called. * * Dynamic data is obtained when any of the following properties/methods is requested: @@ -722,6 +722,7 @@ class course_modinfo { * - {@link cm_info::set_user_visible()} * - {@link cm_info::set_on_click()} * - {@link cm_info::set_icon_url()} + * - {@link cm_info::override_customdata()} * Any methods affecting view elements can also be set in this callback. * * Stage 3 (view data). @@ -1422,6 +1423,7 @@ class cm_info implements IteratorAggregate { * @return mixed Optional custom data stored in modinfo cache for this activity, or null if none */ private function get_custom_data() { + $this->obtain_dynamic_data(); return $this->customdata; } @@ -1679,6 +1681,16 @@ class cm_info implements IteratorAggregate { $this->onclick = $onclick; } + /** + * Overrides the value of an element in the customdata array. + * + * @param string $name The key in the customdata array + * @param mixed $value The value + */ + public function override_customdata($name, $value) { + $this->customdata[$name] = $value; + } + /** * Sets HTML that displays after link on course view page. * @param string $afterlink HTML string (empty string if none)