Problem/Motivation
The description for BodyAdjuster form says:
This field may support tokens or Twig template syntax – please check the supplied default policy for possible values.
We should instead help people out. This issue covers the tokens - see #3270408: Email body policy form should show available token browser and TWIG variables for the tokens.
Steps to reproduce
Edit a policy and add a body element
Workaround
- Look at the default installed policy - this will often use most of the available variables
- Look at the code in the EmailBuilder. The variables are set with
setVariable().
Proposed resolution
1) Add new parameter to the @EmailBuilder annotation: variables = array variable name => description.
2) Make the EmailBuilder definition available in the form
- Add MailerPolicy::getBuilderDefinition()
- Deprecate MailerPolicy::getCommonAdjusters(), as it's easy to get from the above
- In
PolicyEditForm::form(), call$this->entity->getBuilderDefinition()and store the result in the form.
3) Use the annotations in BodyEmailAdjuster::settingsForm(). Display the variables with '#type' => 'details', and set #value based on the variables annotation.
Example
ContactPageEmailBuilder:
variables = {
"form" = "BLAH",
"form_url" = "BLAH",
"recipient_name" = "BLAH",
"recipient_edit_url" = "BLAH",
}
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork symfony_mailer-3404625
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
abyss commentedUpdated the title and description as it was misplaced with #3270408: Email body policy form should show available token browser and TWIG variables.
Comment #3
abyss commentedComment #5
abyss commented@AdamPS, I added display of TWIG variables in the BodyEmailAdjuster.
But I would like to clarify, from which version it is better to note that getCommonAdjusters is deprecated, and in which version it should be removed?
Comment #6
adamps commentedGreat thanks I'll take a look. It would be deprecated in 1.4.1 and removed in 2.0.0.
Comment #7
adamps commentedYes it looks very good. I didn't have a chance to test it yet, however I reviewed the code in the MR and made a few simple comments.
Comment #8
abyss commented@AdamPS, I made changes as per the comments in MR and added a deprecated message for MailerPolicyInterface::getCommonAdjusters.
If you have any other suggestions, I will be happy to add them.
Comment #9
adamps commentedGreat thanks, it's better. I tested it now and I like it. I made some more comments in the MR - they should all be quick and easy.
Two bigger comments:
1) Variables can also be used in SubjectEmailAdjuster and we should do the same. Please put the code in a function (don't just copy it😃) e.g. MailerHelperInterface::showReplacementHelp()
2) It would be great to have a test. At the end of TestEmailTest::testTest(), add a call
$this->submitForm([], 'Edit');then can check that the page contains the replacement pattern for day.Comment #10
adamps commentedActually the are issues open to use tokens in other places too: e.g. plain text body or addresses. So perhaps we should have the variable/token helpers on the form just once - in PolicyEditForm, after all the adjusters. Then for each adjuster that accepts tokens/variables we can put a message to say that.
Comment #11
adamps commentedOK if you can do it for the email body then that's already good. We can raise a follow on issue for the other places.
Comment #12
adamps commentedRejoining with #3270408: Email body policy form should show available token browser and TWIG variables
Many thanks @abyss your MR was a big help.