Skip to content

Commit

Permalink
MDL-72658 lang: Let welcome message use other than just firstname
Browse files Browse the repository at this point in the history
The patch allows for strings welcomeback and welcometosite to be
customised and use other user names than just the firstname.

Supported are placeholder properties matching all known name fields:
firstnamephonetic, lastnamephonetic, middlename, alternatename,
firstname and lastname. Special values fullname and alternativefullname
are supported, too.

By default, the firstname is kept for compatibility with the original
feature design.
  • Loading branch information
mudrd8mz committed Sep 23, 2021
1 parent 214adb7 commit 3722466
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lang/en/moodle.php
Expand Up @@ -2266,8 +2266,8 @@
$string['weekhide'] = 'Hide this week from {$a}';
$string['weeklyoutline'] = 'Weekly outline';
$string['weekshow'] = 'Show this week to {$a}';
$string['welcomeback'] = 'Welcome back, {$a}! 👋';
$string['welcometosite'] = 'Welcome, {$a}! 👋';
$string['welcomeback'] = 'Welcome back, {$a->firstname}! 👋';
$string['welcometosite'] = 'Welcome, {$a->firstname}! 👋';
$string['welcometocourse'] = 'Welcome to {$a}';
$string['welcometocoursetext'] = 'Welcome to {$a->coursename}!
Expand Down
12 changes: 11 additions & 1 deletion lib/classes/user.php
Expand Up @@ -1189,7 +1189,17 @@ public static function welcome_message(): ?lang_string {
$messagekey = 'welcometosite';
set_user_preference('core_user_welcome', time());
}
return new lang_string($messagekey, 'core', $USER->firstname);

$namefields = [
'fullname' => fullname($USER),
'alternativefullname' => fullname($USER, true),
];

foreach (\core_user\fields::get_name_fields() as $namefield) {
$namefields[$namefield] = $USER->{$namefield};
}

return new lang_string($messagekey, 'core', $namefields);
};
return null;
}
Expand Down

0 comments on commit 3722466

Please sign in to comment.