From 3dec4c6ce3a526b6bcee098f53903d0bea246da4 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Thu, 12 Mar 2020 00:55:20 +1100 Subject: [PATCH] MDL-68148 core_user: avoid multiple enrol buttons with the same id --- enrol/manual/lib.php | 10 +++++++--- user/index.php | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index 24e312260ad..2e052760c56 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -197,14 +197,14 @@ class enrol_manual_plugin extends enrol_plugin { global $CFG, $PAGE; require_once($CFG->dirroot.'/cohort/lib.php'); + static $called = false; + $instance = null; - $instances = array(); foreach ($manager->get_enrolment_instances() as $tempinstance) { if ($tempinstance->enrol == 'manual') { if ($instance === null) { $instance = $tempinstance; } - $instances[] = array('id' => $tempinstance->id, 'name' => $this->get_instance_name($tempinstance)); } } if (empty($instance)) { @@ -222,7 +222,11 @@ class enrol_manual_plugin extends enrol_plugin { $context = context_course::instance($instance->courseid); $arguments = array('contextid' => $context->id); - $PAGE->requires->js_call_amd('enrol_manual/quickenrolment', 'init', array($arguments)); + if (!$called) { + $called = true; + // Calling the following more than once will cause unexpected results. + $PAGE->requires->js_call_amd('enrol_manual/quickenrolment', 'init', array($arguments)); + } return $button; } diff --git a/user/index.php b/user/index.php index eb33740b8e7..df921baa32c 100644 --- a/user/index.php +++ b/user/index.php @@ -409,6 +409,8 @@ echo ''; // Userlist. $enrolrenderer = $PAGE->get_renderer('core_enrol'); echo '
'; +// Need to re-generate the buttons to avoid having elements with duplicate ids on the page. +$enrolbuttons = $manager->get_manual_enrol_buttons(); foreach ($enrolbuttons as $enrolbutton) { echo $enrolrenderer->render($enrolbutton); }