Commit fc238f32 authored by jun's avatar jun Committed by Sara Arjona
Browse files

MDL-70815 completion: Cast custom data to array

Since cm_info::customdata can be of any type, we need to cast it to an
array first before checking for custom completion rules. Otherwise,
an exception can be thrown (e.g. customdata has been set as an stdClass)
parent 5a7c629f
......@@ -96,8 +96,9 @@ abstract class activity_custom_completion {
public function get_available_custom_rules(): array {
$rules = static::get_defined_custom_rules();
$availablerules = [];
$customdata = (array)$this->cm->customdata;
foreach ($rules as $rule) {
$customrule = $this->cm->customdata['customcompletionrules'][$rule] ?? false;
$customrule = $customdata['customcompletionrules'][$rule] ?? false;
if (!empty($customrule)) {
$availablerules[] = $rule;
}
......
......@@ -1107,8 +1107,10 @@ class completion_info {
// Custom activity module completion data.
// Cast custom data to array before checking for custom completion rules.
$customdata = (array)$cm->customdata;
// Return early if the plugin does not define custom completion rules.
if (empty($cm->customdata['customcompletionrules'])) {
if (empty($customdata['customcompletionrules'])) {
return [];
}
......@@ -1120,7 +1122,7 @@ class completion_info {
/** @var activity_custom_completion $customcmcompletion */
$customcmcompletion = new $cmcompletionclass($cm, $userid);
foreach ($cm->customdata['customcompletionrules'] as $rule => $enabled) {
foreach ($customdata['customcompletionrules'] as $rule => $enabled) {
if (!$enabled) {
// Skip inactive completion rules.
continue;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment