From 372246689252b427bab2b4fed65d9b336c8705a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Thu, 23 Sep 2021 20:57:22 +0200 Subject: [PATCH] MDL-72658 lang: Let welcome message use other than just firstname 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. --- lang/en/moodle.php | 4 ++-- lib/classes/user.php | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 577fd3648c9..67e6db0619d 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -2266,8 +2266,8 @@ $string['weeks'] = 'weeks'; $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}! diff --git a/lib/classes/user.php b/lib/classes/user.php index c1e81c63198..d22520999fe 100644 --- a/lib/classes/user.php +++ b/lib/classes/user.php @@ -1189,7 +1189,17 @@ class core_user { $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; }