MDL-83432 enrol_manual: reference correct role in welcome message.

This commit is contained in:
Paul Holden
2024-10-18 15:12:44 +01:00
parent 09880d7d78
commit e792dbbe0b
4 changed files with 23 additions and 1 deletions
@@ -0,0 +1,13 @@
issueNumber: MDL-83432
notes:
core_enrol:
- message: >-
The `after_user_enrolled` hook now contains a `roleid` property to allow
for listeners to determine which role was assigned during user enrolment
(if any)
The base enrolment `enrol_plugin::send_course_welcome_message_to_user`
method also now accepts a `$roleid` parameter in order to correctly
populate the `courserole` placeholder
type: changed
@@ -39,6 +39,8 @@ class after_user_enrolled {
public readonly stdClass $enrolinstance,
/** @var stdClass The user enrolment instance */
public readonly stdClass $userenrolmentinstance,
/** @var int|null The assigned role ID */
public readonly ?int $roleid = null,
) {
}
@@ -40,6 +40,7 @@ class user_enrolment_callbacks {
userid: $hook->get_userid(),
sendoption: $instance->customint1,
message: $instance->customtext1,
roleid: $hook->roleid,
);
}
}
+7 -1
View File
@@ -2159,6 +2159,7 @@ abstract class enrol_plugin {
$hook = new \core_enrol\hook\after_user_enrolled(
enrolinstance: $instance,
userenrolmentinstance: $ue,
roleid: $roleid,
);
\core\di::get(\core\hook\manager::class)->dispatch($hook);
@@ -3644,18 +3645,23 @@ abstract class enrol_plugin {
* @param int $userid User ID.
* @param int $sendoption Send email from constant ENROL_SEND_EMAIL_FROM_*
* @param null|string $message Message to send to the user.
* @param int|null $roleid The assigned role ID
*/
public function send_course_welcome_message_to_user(
stdClass $instance,
int $userid,
int $sendoption,
?string $message = '',
?int $roleid = null,
): void {
global $DB;
$context = context_course::instance($instance->courseid);
$user = core_user::get_user($userid);
$course = get_course($instance->courseid);
$courserole = $DB->get_record('role', ['id' => $instance->roleid]);
// Fallback to the instance role ID if parameter not specified.
$courseroleid = $roleid ?: $instance->roleid;
$courserole = $DB->get_record('role', ['id' => $courseroleid]);
$a = new stdClass();
$a->coursename = format_string($course->fullname, true, ['context' => $context, 'escape' => false]);