User tests: Successful: Unsuccessful:
Pull Request for Issue # .
Allow to read existing template data in the MailTemplate.
Currently it is complicated to determine the exact content is associated with MailTemplate.
Example during User registration it is impossible to load parameter from User Profile plugin in onMailBeforeRendering event to add them in to email. Because it is impossible to determine for which User it is.
The same can be for any other content associated with MailTemplate.
With new getTemplateData() it should be easy now.
Code review from Maintainers .
OR
Enable Plugin User - Profile.
Create a new User, set the profile value for Country field.
Edit Email Template for "Users: Username Reminder", and change:
Your username: {USERNAME}
to:
Your username: {USERNAME}
Your country: {PROFILE.COUNTRY}
Add 'onMailBeforeRendering' => 'onMailBeforeRendering', after:
And at the end of the file (before last }) add:
public function onMailBeforeRendering(\Joomla\CMS\Event\Mail\BeforeRenderingMailTemplateEvent $event)
{
if ('com_users.reminder' === $event->getTemplateId()) {
$emailTmpl = $event->getTemplate();
$data = $emailTmpl->getTemplateData();
$userId = ArrayHelper::getValue($data, 'id', 0, 'int');
if ($userId) {
$key = 'profile.country';
$db = $this->getDatabase();
$query = $db->createQuery()->select($db->quoteName('profile_value'))
->from($db->quoteName('#__user_profiles'))
->where($db->quoteName('user_id') . ' = :userid')
->where($db->quoteName('profile_key') . ' = :key')
->bind(':userid', $userId, ParameterType::INTEGER)
->bind(':key', $key, ParameterType::STRING);
$db->setQuery($query);
$data[$key] = $db->loadResult() ?: '';
$emailTmpl->addTemplateData($data);
}
}
}Please select:
| Status | New | ⇒ | Pending |
| Category | ⇒ | Libraries |
I have tested this item ✅ successfully on 77e19f7
I tested this issue, and it was tested successfully.
I have tested this item 🔴 unsuccessfully on 77e19f7
Please see below email content
Hello,
A username reminder has been requested for your Your Joomla! Site hosted with .net account.
Your username: username
Your country: {PROFILE.COUNTRY}
To login to your account, select the link below.
https://siteurl/index.php/component/users/login
Thank you.
I have tested this item ✅ successfully on 77e19f7
I have successfully tested this PR.
BEFORE the PR patch, we also get an error:
0 Call to undefined method Joomla\CMS\Mail\MailTemplate::getTemplateData()
After patch it works!
| Status | Pending | ⇒ | Ready to Commit |
RTC
I have tested this item ✅ successfully on 77e19f7
I have successfully tested this PR.
BEFORE the PR patch, you get an error:
0 Call to undefined method Joomla\CMS\Mail\MailTemplate::getTemplateData()
which seems logical as the code is not in line elsewhere with the function that you are adding.
AFTER the PR patch, works prefectly well ;) with or without site caching, with or without Error Reporting to Simple or Maximum, no console errors either.
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46711.