diff --git a/public/course/tests/reportbuilder/datasource/participants_test.php b/public/course/tests/reportbuilder/datasource/participants_test.php index 30225c67ca0..efbaf546f38 100644 --- a/public/course/tests/reportbuilder/datasource/participants_test.php +++ b/public/course/tests/reportbuilder/datasource/participants_test.php @@ -85,7 +85,7 @@ final class participants_test extends core_reportbuilder_testcase { $this->assertEquals([ ["{$coursetwo->fullname}", - "" . fullname($userone) . "", 'Self enrolment (Student)'], + "" . fullname($userone) . "", 'Self enrolment as \'Student\''], ["{$courseone->fullname}", "" . fullname($usertwo) . "", 'Manual enrolments'], ["{$courseone->fullname}", diff --git a/public/enrol/self/lang/en/enrol_self.php b/public/enrol/self/lang/en/enrol_self.php index 0a721a3f21b..e8e6f27babf 100644 --- a/public/enrol/self/lang/en/enrol_self.php +++ b/public/enrol/self/lang/en/enrol_self.php @@ -33,6 +33,7 @@ $string['defaultrole'] = 'Default role assignment'; $string['defaultrole_desc'] = 'Select role which should be assigned to users during self enrolment'; $string['deleteselectedusers'] = 'Delete selected user enrolments'; $string['editselectedusers'] = 'Edit selected user enrolments'; +$string['enroledas'] = '{$a->enrol} as \'{$a->role}\''; $string['enrolenddate'] = 'End date'; $string['enrolenddate_help'] = 'If enabled, users can enrol themselves until this date only.'; $string['enrolenddaterror'] = 'Enrolment end date cannot be earlier than start date'; diff --git a/public/enrol/self/lib.php b/public/enrol/self/lib.php index d8d7c10cb44..5f417238268 100644 --- a/public/enrol/self/lib.php +++ b/public/enrol/self/lib.php @@ -83,17 +83,20 @@ class enrol_self_plugin extends enrol_plugin { public function get_instance_name($instance) { global $DB; - if (empty($instance->name)) { - if (!empty($instance->roleid) and $role = $DB->get_record('role', array('id'=>$instance->roleid))) { - $role = ' (' . role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING)) . ')'; - } else { - $role = ''; - } - $enrol = $this->get_name(); - return get_string('pluginname', 'enrol_'.$enrol) . $role; - } else { - return format_string($instance->name); + if (!empty($instance->name)) { + return format_string($instance->name, true, ['context' => context_course::instance($instance->courseid)]); } + + $enrolname = get_string('pluginname', 'enrol_' . $this->get_name()); + if (!empty($instance->roleid)) { + $role = $DB->get_record('role', ['id' => $instance->roleid]); + if ($role) { + $rolename = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING)); + return get_string('enroledas', 'enrol_self', ['enrol' => $enrolname, 'role' => $rolename]); + } + } + + return $enrolname; } public function roles_protected() { diff --git a/public/enrol/self/tests/behat/self_enrolment.feature b/public/enrol/self/tests/behat/self_enrolment.feature index 75c52f3cfef..e4afaada48d 100644 --- a/public/enrol/self/tests/behat/self_enrolment.feature +++ b/public/enrol/self/tests/behat/self_enrolment.feature @@ -162,7 +162,7 @@ Feature: Users can auto-enrol themself in courses where self enrolment is allowe Scenario: Self-enrolment enabled with simultaneous guest access Given I log in as "teacher1" And I am on the "Course 1" "enrolment methods" page - And I click on "Enable" "link" in the "Self enrolment (Student)" "table_row" + And I click on "Enable" "link" in the "Self enrolment as 'Student'" "table_row" And I click on "Edit" "link" in the "Guest access" "table_row" And I set the following fields to these values: | Allow guest access | Yes |