Hello,
I’m theming some user emails, for example the password reset notification email, and I think it would be useful to send the whole user object to the mail template if you want to take the firstname lastname or any other fields you attached to the user :
Here is the actual function :
public function sendPasswordResetNotification($token)
{
$url = $this->passwordResetUrl ?: Cms::entryUrl('resetPassword');
$url .= str_contains($url, '?') ? '&' : '?';
$url .= http_build_query([
'reset' => $token,
'email' => $this->getEmailForPasswordReset()
]);
$data = [
'url' => $url,
'token' => $token,
'count' => Config::get('auth.passwords.users.expire')
];
$data += $this->getNotificationVars();
Mail::send('user:recover_password', $data, function($message) {
$message->to($this->email, $this->full_name);
});
}
I saw that the method getNotificationVars() add some more variables here
public function getNotificationVars(): array
{
$vars = [
'full_name' => $this->full_name,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'login' => $this->login,
'email' => $this->email,
'username' => $this->username,
];
// Extensibility
$result = Event::fire('rainlab.user.getNotificationVars', [$this]);
if ($result && is_array($result)) {
$vars = call_user_func_array('array_merge', $result) + $vars;
}
return $vars;
}
But why not adding the whole user object in case you extended it ?
Thank you