User tests: Successful: Unsuccessful:
This PR adds a way to modify the mails that are send by the system in a GUI and with a larger range of possibilities than with the current system of simple translation strings. Extensions have to register the mails that they want to send and then can use an API to render those mails.
An extension has to add its templates via MailTemplate::addTemplate()
during installation or whenever it is doing its setup. This inserts a row for each mail template into #__mail_templates, with a template_id, an empty language field, translation strings for subject, body and optionally htmlbody and in the params field the available tags in the template. The template_id has to be of the format {extension}.{sub-identifier}, for example "com_config.test_mail". This is not restricted to components, but it requires a translation file in the administrator language folder.
If there is no modified mail template, the translated translation strings are used to send the mails.
The GUI is located in com_mails and is in the System menu in the backend below the global configuration item. All the templates are listed in that view and you can then click on the respective flag to edit the template for that language. You can enable or disable editing the different fields. The idea behind this is, that you can revert changes to the templates by going back to the original translation strings.
Next to the editors, you have the available tags, which can be inserted into the text by clicking on them. These also work in the subject, but have not been listed here separately.
To send a mail, the code could look like this:
$mailer = new MailTemplate('com_config.test_mail', $user->getParam('language', $app->get('language')), $mail);
$mailer->addTemplateData(array('sitename' => $app->get('sitename'), 'method' => Text::_('COM_CONFIG_SENDMAIL_METHOD_' . strtoupper($mail->Mailer))));
$mailer->addRecipient($app->get('mailfrom'), $app->get('fromname'));
$mailer->send();
You create a MailTemplate object with the ID of your mail template and the language that you want this in, then add the data that should be replaced in the template as associative array and the recipient and then send it.
{key}...{/key}
and repeat that for every array in the array... I guess you catch what I'm trying to say. This can be nested infinitely deep.Right now there is one template in the system for the test mail in the global configuration. You can modify the template for your language (install additional languages and create content languages for more languages in the templates) and then test it by clicking the test button in the mail settings.
I've rewritten this PR to include features that were previously only advertised but not included and did some more cleanup work.
I'm looking forward to your feedback.
This PR is supported by Showcast.de, where we have been using a similar system for quite some time now.
Status | New | ⇒ | Pending |
Category | ⇒ | SQL Administration com_admin Postgresql com_config com_cpanel Language & Strings Installation Libraries |
Labels |
Added:
?
?
|
Instead of using a table, can we not work with plugin events to collect the available mail templates? It would make the thing more dynamic as often the strings are not static.
As components, which do have that functionality already self made, in their submenu and custom fields and categories are there too, would it be possible to offer mail template menu links for a component. The idea behind it is that people install a component and then do set it up. So it would be good when they do not have to leave the context of the component and do navigate away from it to set up the mails.
Beside that I really like that feature!
@laoneo I thought about several ways how to do this, but storing the templates in a table is the only thing that doesn't escalate into a horrible abomination of system. If you are talking about the available tags: You can already extend those via a plugin event when sending the mails and I'm working on adding the event when rendering the tags.
Ok, I did some more work and you should be able to save the changed templates now. Unfortunately I have some issues with the sessions and I'm getting kicked out of my installation on each click... idk. Anyway, it would be nice to get some feedback from you guys now.
When editing a template, somehow I got a broken editor, not sure if it related to the PR.
Sending cannot test currently, have to fix my email config.
The broken editor is a general issue when you have 2 different editors on the same page. That is something that we have to look into in another issue.
Pretty sure that was resolved in J3
Title |
|
Title |
|
So I have tested (Text version) and it looks good to me (except broken editing of HTML version).
I was able to add custom Tags via plugin events, and all worked:
/**
* @param string $mail_id
* @param CMSObject $mail
*/
public function onMailBeforeTagsRendering($mail_id, $mail)
{
if ($mail_id === 'com_config.test_mail')
{
$mail->params['tags']['beer'] = 'beer';
$mail->params['tags']['bear'] = 'bear';
}
}
/**
* @param string $mail_id
* @param MailTemplate $mailTemplate
*/
public function onMailBeforeRendering($mail_id, $mailTemplate)
{
if ($mail_id === 'com_config.test_mail')
{
$mailTemplate->addTemplateData(array(
'beer' => 'Beeeer',
'bear' => 'Beeeeaaaaaar'
));
}
}
Couple notes:
What about the possibility to offer components to add the mailer list to their submenu? People install an extension and then they want to set it up. Editing mail templates is one task of it. Like it is now you have to go to a menu item buried somewhere in the system menu. Similar to what we have now with categories and fields. The user can stay in the context.
Beside that I really love that functionality. Code review will come later, except that I would move the it to com_mailto.
@laoneo I'm torn on your proposal. I understand your proposal, but I do have two issues with going that way. The first is, that there are components that only send one mail (com_config, com_joomlaupdate) and it is pretty much overkill to have an extra submenu entry, list view, etc. for just this one mail template and the second is that this would only work for components. But I want this to be also used by plugins. For example, a customer of mine uses a plugin to send a mail to a user when the user is deleted. I don't know how that one would be accessible via the GUI for a plugin.
Maybe we can simply keep it the way it is now and add a second mode, where it filters for a certain extension and displays that extensions submenu when called by a specific parameter? That could be implemented in a second step when this one is merged.
What about the possibility to offer components to add the mailer list to their submenu?
I am agree with @Hackwar , this not really need for now, just a filter can be enough.
And I think it will be not that often used thing, like tags or fields.
Just an one more configuration possibilities.
So at least filters should be added before merging.
Filters have been added. Please consider this for merging and then we can add a bunch of other templates to this and add more features...
I've basically started over with this PR and did a lot of changes. There are still a few JS issues in the edit screen, where I would kindly ask for some help. I'm just not really a JS guy. Please read the initial text of this PR to know about all the changes that I did.
@Fedik The switch to enable/disable the input fields when editing a mail template don't work right and you can click on a tag and it is added to the input field, even though they are disabled.
I have no idea how we can add the nested tags in a good way into the UI. Maybe that is really something for a future PR... I also don't know how we can handle the same tags in plaintext and html. I'm open for suggestions (and contributions to this PR)
I had a quick look at the PR and have few feedback/questions:
Look like we removed two fields custom_data, system_data from #__extensions table, so the installation SQL in this PR won't work. You need to remove two fields from INSERT command
The code in edit, save methods of TemplateController and getItem, save methods of TemplateModel is almost the same/duplicate code of it's parent class. Why is that? I guess it's because you don't use id as primary key of #__mail_templates table instead of using id as most of Joomla tables. Personal, I don't like these duplicate code, so unless there are special reason, I would use id as primary key to remove these duplicate code.
We would have to find out how to handle multilingual website. From what I see, for each language, we need one record for a mail template. So how we populate these records on install? And how when user installs a new language to the site?
I have the feeling that the MailTemplate is doing more than it needs. I could not think of a case when I could define attachments, BCC/CC emails... when the mail template is inserted into database. If I have to add attachments, I would do that in $mail object before passing it to MailTemplate, same for BCC/CC emails. These data usually dynamic data, not static.
These are few minor issues with the code, but I will review it later, depends on the decision for #2
to 1. I will have a look at that.
to 2. That is related to using a master template and then the different languages. The key for a template is always the identifier com_config.test_mail
and then the language. I don't like that duplicate code either, but it is far better than the alternative of introducing an unnecessary integer ID here.
to 3. This IS ready for multilingual websites. Each mail template in the beginning consists of a master template that has translateable language strings. If there is no language specific mail template, then it will use the master template and simply translate the language strings. You can then go and edit the master template for a specific language and save that and it will generate a language specific template. That is why there are switches next to the subject and bodys. You can switch using those language strings or your custom template on or off.
to 4. The static attachments is aimed at shops, etc. which want to send out their ToS as a PDF via mail. I could come up with several more scenarios. The BCC I personally would use to have a log of the mails that my system has sent out and to be able to test this over a certain period of time.
Hello Sorry I'm jumping on this a bit late. There is a PR we are currently working on to merge our tj-notifications system in Joomla to allow easy editing of all system emails and provide a centralised notification system. My Original detailed blog on this is lost as it was hosted on joomla.com and i missed renewing it :( .
However the GitHub can be checked here : https://github.com/techjoomla/TJ-Notifications/wiki This is in use now for 2 odd years in production and is pretty stable..
There is a little bit of an overlap on this PR on it. In this PR we would simply need to add the Notification magic method in all places that currently triggers an email. This will allow further extension to notifications via SMS, Push etc.
In addition to the notifications, I would also be willing to donate the code of Email Beautifier/TJNotifications (or merge it in this PR to bring any features we have there that are missing here).
I tried to use patch tester to install this and I got this message ×
Error
The file marked for modification does not exist: administrator/components/com_config/Model/ApplicationModel.php
Are you using this on a Joomla 4.0 installation?
Are you using this on a Joomla 4.0 installation?
Ah of course, whoops
@Hackwar please look Hackwar#26
A note: I would remove MailsHelper::mailtags
(it hardcoded HTML) and use a "sub template" instead (eg edit_mailtaglist.php
).
One issue still left, with HTML Body editor. If it initialized as Disabled it not possible to enable it (and vice versa), we do not have an API for it.
Maybe we can leave it always enabled (on initial state) for now or? And use PHP to prevent of saving changes if "switcher == 0"
Category | SQL Administration com_admin Postgresql com_config com_cpanel Language & Strings Installation Libraries | ⇒ | SQL Administration com_admin Postgresql com_config com_cpanel Language & Strings JavaScript Repository Installation Libraries |
Your request has nothing to do with this PR and is completely unrelated. You also already got a decision in your issue regarding that.
Category | SQL Administration com_admin Postgresql com_config com_cpanel Language & Strings Installation Libraries JavaScript Repository | ⇒ | Administration com_admin com_config com_cpanel Installation JavaScript Libraries Postgresql Repository SQL |
Category | SQL Administration com_admin Postgresql com_config com_cpanel Installation Libraries JavaScript Repository | ⇒ | SQL Administration com_admin Postgresql com_config com_cpanel |
Labels |
Removed:
?
|
I installed via patch tester and then I also discovered com_mail but when I go to the system link it says 404 component not found. Did I do something incorrectly? Also the language string under system is broken. I don't find anything in components only in system, but I think that is right according to the PR?
Category | SQL Administration com_admin Postgresql com_config com_cpanel | ⇒ | SQL Administration com_admin Postgresql com_config com_cpanel Language & Strings JavaScript Repository NPM Change Installation Libraries |
Labels |
Added:
?
NPM Resource Changed
|
This PR has unfortunately gathered some dust in the last few months... Today @wilsonge and I tried to make it all work again and we partially succeeded. The component works 98%, but there are 2 issues remaining that I can't fixed:
If someone could help out with this, I'd be really happy.
The switcher elements have a legend attached to them, which I'd rather have not visible. How can I remove that? @brianteeman?
@Hackwar are you referring to this
Thats because you dont have a label in the xml.
The switcher elements have a legend attached to them, which I'd rather have not visible. How can I remove that? @brianteeman?
@Hackwar are you referring to this
Thats because you dont have a label in the xml.
When I'm adding a label, it is still displaying that label. I don't want to have anything there, just the switcher.
How would anyone know what the switch is for?
Not sure I understand all of this, as it looks pretty hard for non-coders to create their own mail template, but here is a remark concerning language based on the example proposed for send mail test.
Using type="contentlanguage"
looks wrong to me because we may have a site with multiple languages but NOT set as a multilingual site, i.e. where the Content Languages have been deleted because they are useless (thereefore no specific flag or sef).
In the case of sending test mail, which is done from backend, it should imho just depend on the admin language in use. Therefore filtering by Content Language as well as using getContentLanguages
instead of getInstalledLanguages
with client administrator is wrong.
Hint: see isAdminMultilang
for admin modules.
There is no interest in letting normal users create their own templates. This is a way for an extension to allow for complex mails with translated content. You can edit existing templates, not create new ones.
We don't know if a template is used in the frontend or backend when editing the template. So I wont know if to use isAdminMultilang
. The same issue is with the contentlanguages vs installed languages. I have to choose one of the two for the form XML and as we had this discussion in the past, I chose the content languages, among other reasons because you might have several content languages for one installed language.
I chose the content languages, among other reasons because you might have several content languages for one installed language.
It is wrong in this test case as I clearly demonstrated.
Never heard of anyone keeping content languages and only one installed language for ever: this makes no sense at all and would be totally useless.
Now that you have added labels I am even more confused about what they do
Now that you have added labels I am even more confused about what they do
How about you click them?
Now that you have added labels I am even more confused about what they do
How about you click them?
You shouldnt have to in order to understand their purpose. But I will install the branch and look
maybe something like "Customize HTML body" or "Edit HTML email" can be better for label?
or "enable editing"
I think the best solution would be to write a ten page essay as label...
Might have helped me if I had noticed that there was some JS in this PR - oops
Edit Subject yes/no
Edit Body yes/no
@brianteeman email has 2 body, for a plain text and for a html.
"Edit Body yes/no" maybe not enough
Edit Subject yes/no
Edit Body yes/no
Edit HTML Body yes/no
done
Thanks
It should not depend on Content Languages
I can understand a reason why it made like that.
@Hackwar @infograf768 what do you think about next approach:
language = *
<h1>{TEXT:HELLO_USER}</h1>
<p>{TEXT:WELCOME_MESSAGE}</p>
In theory it will allow to simplify the thing for Users a bit, will use a default (active) language, and will separate Site/Admin.
Is it will be hard to implement?
I wonder if you guys actually looked at this in depth. You don't have to create any templates at all, because it will always fall back on a translation string. IF you create your own template, it takes that translation string, translates it and prepopulates the respective input with that. In that translated string, you already have placeholders for the actual data. You can then reorder that whichever way you want or add it multiple times. It even contains the code to use subtemplates, even though that is not available via the GUI yet. Something for 4.1 or 4.2.
I don't see any reason to change it to what @Fedik described above.
The one thing that is missing to make this truly useful is the ability to send yourself a test email
The one thing that is missing to make this truly useful is the ability to send yourself a test email
Seems slightly non-trivial because you'd need to manually add all the data that can be injected with tags into the body of the email.
Category | SQL Administration com_admin Postgresql com_config com_cpanel Language & Strings JavaScript Repository NPM Change Installation Libraries | ⇒ | SQL Administration com_admin Postgresql com_config com_menus Language & Strings JavaScript Repository NPM Change Installation Libraries |
Conflict fixed. As far as I'm concerned this will do for feature completeness for now. I kind of agree with @brianteeman 's comment about test mails but also understand that it can be complicated for this and am happy to leave this for a future Joomla version.
I believe the only thing left here beyond testing is to make a final call whether to use content languages or installed languages for the emails (I leave that to people who actually build multilang sites) - probably one for a Production Department call @HLeithner ?
You still need some sort of value however which is going to be context specific
I believe the only thing left here beyond testing is to make a final call whether to use content languages or installed languages for the emails (I leave that to people who actually build multilang sites) - probably one for a Production Department call @HLeithner ?
My opinion is that it should be content specific but last time I tried (it's a long time ago) content languages with out a similar installed language doesn't work properly so I didn't used it.
Having here the "Pizza-Bugs-and-Fun" with @roland-d I tried to get this PR tested. However, I had a clean installation of Joomla 4 and applied the patch. First, the extension didn't get corrected installed, i.e. the mysql DB was not updated correctly, when I opened http://localhost/joomla-cms3/administrator/index.php?option=com_mails&view=templates locally this error appeard.
I updated the DB myself but then this error appeared:
What can I do to get the patch run?
Thanks
@Hackwar I sent PR Hackwar#33 to fix the SQL errors.
You should add to the test instructions that you have to delete the autoload_psr4.php file (/ libraries) and the Javascript files have to be rebuilt (npm run build: js)
Category | SQL Administration com_admin Postgresql com_config Language & Strings JavaScript Repository NPM Change Installation Libraries com_menus | ⇒ | SQL Administration com_admin Postgresql com_config com_menus Language & Strings JavaScript Repository NPM Change Installation |
Status | Pending | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2019-09-28 00:28:59 |
Closed_By | ⇒ | wilsonge |
Merging this as a starting point as the basics work. I fully accept there needs to be some work here as we move through getting 4.0 to stable. Personally for example the way if you enable html mails don't show the text at all for the sample mail is confusing (although having dived through the code I think I finally understand the logic of why). So let's start with this get some user testing done as it ends up in the nightlies and see how things go.
Thanks @Hackwar
No, right now the workflow is not implemented here. I'm open to improve this in the future; for 4.0 I would keep it the way it is and postpone this to 4.1 or similar.
ok cool ! thanks i will be a great function !!!
that a cool feature!