Problem/Motivation

Environment:
Drupal : 9.3.0
Patches Applied To Drupal:
https://www.drupal.org/project/drupal/issues/3180227#comment-13890098

PHP : 8
dBug for Drupal : 2.0.0
Business Rules : 2.0.0-beta1
Patches Applied to Business Rules:
https://www.drupal.org/project/business_rules/issues/3250592
https://www.drupal.org/project/business_rules/issues/2998984#comment-131...
https://www.drupal.org/project/business_rules/issues/3067571#comment-135...
https://www.drupal.org/project/business_rules/issues/3056302#comment-134...

Symfony Mailer : 1.x-dev
Patches Applied to Symfony Mailer:
https://www.drupal.org/project/symfony_mailer/issues/3256190

With Drupal Swift Mailer library no longer being maintained we have decided to move over to the Symfony mailer. Everything else works great with symfony mailer, except the Drupal Business Rules. We are able to send emails in HTML format, but the only problem is that none of the tokens we insert works.

Business Rules
Create Action: Send email
Use site mail as sender: Yes
To: {{current_user->mail}}
Subject: Ticket #[node:nid]
Mail format: HTML

Symfony Mailer:
Add Policy: Business Rules
SUB-TYPE: All
Add Element: Body

When the body element is added in symfony mailer the email is sent out, the user will receive the HTML formatted email, but tokens wont be replaced. When you don't add the body element in Symfony mailer, the user will receive the email, but not in HTML format and tokens will be replaced.

Steps to reproduce

Set up environment as above and test between adding and removing a body element formatted with a HTML email with Tokens in the policy created.

Comments

Duvan.Slabbert created an issue. See original summary.

adamps’s picture

Title: Drupal Business Rules Tokens. » System emails sent from actions missing token replacement
Priority: Major » Normal

Thanks for the report. I believe the problem is that system_mail() replaces tokens but SystemEmailBuilder::preRender() does not. The same would happen whenever an email action is used in any module.

The fix is to use TokenProcessorTrait, similar to UserEmailBuilder.

I will be busy myself for a month or more - patches are welcome.

alex.ksis’s picture

Status: Active » Needs review
StatusFileSize
new1.15 KB

Just adding the trait seems to be working fine.

loze’s picture

Patch in #3 works for me, thank you.

adamps’s picture

Status: Needs review » Needs work

Great thanks @alex.ksis and @loze.

Please can you undo the unrelated change to code alignment? The existing alignment is used consistently throughout this module and I prefer it. If we are going to change it (which I would like to debate before deciding) then let's do it properly throughout the code, in another issue.

adamps’s picture

Status: Needs work » Needs review
StatusFileSize
new1.05 KB

  • AdamPS committed 51c26ee on 1.x authored by alex.ksis
    Issue #3258789 by AdamPS, alex.ksis, Duvan.Slabbert, loze: System emails...
adamps’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.