From 9b5eb38f5555bea94eb1ba493ba5965ec1885693 Mon Sep 17 00:00:00 2001 From: David Matamoros Date: Fri, 20 Nov 2020 17:09:37 +0100 Subject: [PATCH] MDL-63683 enrol: Fix plugin settings when no role has student archetype --- enrol/cohort/settings.php | 2 +- enrol/database/settings.php | 6 +++++- enrol/fee/settings.php | 2 +- enrol/manual/settings.php | 2 +- enrol/mnet/settings.php | 2 +- enrol/paypal/settings.php | 5 ++++- enrol/self/settings.php | 5 ++++- 7 files changed, 17 insertions(+), 7 deletions(-) diff --git a/enrol/cohort/settings.php b/enrol/cohort/settings.php index 8c08a745d8e7c..50cd5dcddc381 100644 --- a/enrol/cohort/settings.php +++ b/enrol/cohort/settings.php @@ -36,7 +36,7 @@ $student = get_archetype_roles('student'); $student = reset($student); $settings->add(new admin_setting_configselect('enrol_cohort/roleid', - get_string('defaultrole', 'role'), '', $student->id, $options)); + get_string('defaultrole', 'role'), '', $student->id ?? null, $options)); $options = array( ENROL_EXT_REMOVED_UNENROL => get_string('extremovedunenrol', 'enrol'), diff --git a/enrol/database/settings.php b/enrol/database/settings.php index 28c75044f2f32..92d0833b3fd5c 100644 --- a/enrol/database/settings.php +++ b/enrol/database/settings.php @@ -86,7 +86,11 @@ $options = get_default_enrol_roles(context_system::instance()); $student = get_archetype_roles('student'); $student = reset($student); - $settings->add(new admin_setting_configselect('enrol_database/defaultrole', get_string('defaultrole', 'enrol_database'), get_string('defaultrole_desc', 'enrol_database'), $student->id, $options)); + $settings->add(new admin_setting_configselect('enrol_database/defaultrole', + get_string('defaultrole', 'enrol_database'), + get_string('defaultrole_desc', 'enrol_database'), + $student->id ?? null, + $options)); } $settings->add(new admin_setting_configcheckbox('enrol_database/ignorehiddencourses', get_string('ignorehiddencourses', 'enrol_database'), get_string('ignorehiddencourses_desc', 'enrol_database'), 0)); diff --git a/enrol/fee/settings.php b/enrol/fee/settings.php index 2f383b8a474cd..50d919ea55513 100644 --- a/enrol/fee/settings.php +++ b/enrol/fee/settings.php @@ -71,7 +71,7 @@ $student = get_archetype_roles('student'); $student = reset($student); $settings->add(new admin_setting_configselect('enrol_fee/roleid', - get_string('defaultrole', 'enrol_fee'), get_string('defaultrole_desc', 'enrol_fee'), $student->id, $options)); + get_string('defaultrole', 'enrol_fee'), get_string('defaultrole_desc', 'enrol_fee'), $student->id ?? null, $options)); } $settings->add(new admin_setting_configduration('enrol_fee/enrolperiod', diff --git a/enrol/manual/settings.php b/enrol/manual/settings.php index 2056c196dc3c1..8dcabcc59516c 100644 --- a/enrol/manual/settings.php +++ b/enrol/manual/settings.php @@ -63,7 +63,7 @@ $student = get_archetype_roles('student'); $student = reset($student); $settings->add(new admin_setting_configselect('enrol_manual/roleid', - get_string('defaultrole', 'role'), '', $student->id, $options)); + get_string('defaultrole', 'role'), '', $student->id ?? null, $options)); } $options = array(2 => get_string('coursestart'), 3 => get_string('today'), 4 => get_string('now', 'enrol_manual')); diff --git a/enrol/mnet/settings.php b/enrol/mnet/settings.php index fc7517faa8905..c74c8e19a0b1a 100644 --- a/enrol/mnet/settings.php +++ b/enrol/mnet/settings.php @@ -36,6 +36,6 @@ $student = reset($student); $settings->add(new admin_setting_configselect_with_advanced('enrol_mnet/roleid', get_string('defaultrole', 'role'), '', - array('value'=>$student->id, 'adv'=>true), $options)); + array('value' => $student->id ?? null, 'adv' => true), $options)); } } diff --git a/enrol/paypal/settings.php b/enrol/paypal/settings.php index 66e0ae4926b12..d9a3a7fea3332 100644 --- a/enrol/paypal/settings.php +++ b/enrol/paypal/settings.php @@ -66,7 +66,10 @@ $student = get_archetype_roles('student'); $student = reset($student); $settings->add(new admin_setting_configselect('enrol_paypal/roleid', - get_string('defaultrole', 'enrol_paypal'), get_string('defaultrole_desc', 'enrol_paypal'), $student->id, $options)); + get_string('defaultrole', 'enrol_paypal'), + get_string('defaultrole_desc', 'enrol_paypal'), + $student->id ?? null, + $options)); } $settings->add(new admin_setting_configduration('enrol_paypal/enrolperiod', diff --git a/enrol/self/settings.php b/enrol/self/settings.php index 6375ea2a10076..cee5d7fc21b60 100644 --- a/enrol/self/settings.php +++ b/enrol/self/settings.php @@ -79,7 +79,10 @@ $student = get_archetype_roles('student'); $student = reset($student); $settings->add(new admin_setting_configselect('enrol_self/roleid', - get_string('defaultrole', 'enrol_self'), get_string('defaultrole_desc', 'enrol_self'), $student->id, $options)); + get_string('defaultrole', 'enrol_self'), + get_string('defaultrole_desc', 'enrol_self'), + $student->id ?? null, + $options)); } $settings->add(new admin_setting_configduration('enrol_self/enrolperiod',