Problem/Motivation
If the token type is not exactly the same as the variable name, the variable is not passed.
I encountered this problem with simplenews and the simplenews-subscriber token type. The variable is called simplenews_subscriber and is therefore not included in the data variable passed to the token service.
Steps to reproduce
Install the simplenews module and sent a subscription email using the subscription block.
All [simplenews-subscriber:....] are not convert.
Proposed resolution
As a workaround, and so as not to change anything, I added a fake token type to the MailerInfo of simplenews.subscriber:
#[MailerInfo(
base_tag: "simplenews.subscriber",
label: new TranslatableMarkup("Simplenews subscriber"),
sub_defs: [
"subscribe" => new TranslatableMarkup("Confirmation"),
"validate" => new TranslatableMarkup("Validate"),
],
required_config: ["email_subject", "email_body"],
token_types: [
"simplenews-subscriber",
"simplenews_subscriber", <-- Quick fix
],
)]It's not a permanent solution, but it does the trick.
Issue fork symfony_mailer-3566176
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
damien laguerre commentedComment #3
adamps commentedThanks for the report. Yes the problem comes from the inconsistency in simplenews tokens, summarised by
simplenews_token_info().I suggest a slightly different fix on line 47:
If anyone can test it, or create a MR that would be a big help.
Comment #4
adamps commentedI confirm the bug. The subscribe and validate emails are unusable for anon subscribers.
Comment #6
adamps commentedSorry the suggestion in #3 was a bit muddled (I was mostly looking at the wrong file
SimplenewsNewsletterMailer.php). It had the right idea to call->setParam('token_data', and this is now done correctly in the MR.Comment #7
adamps commentedThe parts of the MR relating to
use AutowireTrait;aren't part of this fix - it's just some tidy-up I noticed recently and didn't want to create a whole separate MR/issue for.Comment #9
adamps commented