MDL-68148 core_user: avoid multiple enrol buttons with the same id

This commit is contained in:
Shamim Rezaie 2020-03-12 00:55:20 +11:00
parent 8a805e03a4
commit 3dec4c6ce3
2 changed files with 9 additions and 3 deletions

View File

@ -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;
}

View File

@ -409,6 +409,8 @@ echo '</div>'; // Userlist.
$enrolrenderer = $PAGE->get_renderer('core_enrol');
echo '<div class="float-right">';
// 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);
}