Problem/Motivation
Im using symfony_mailer and simplenews together with content_translation.
When creating, translating and dispatching node issues with the given stack, The nodes should be rendered in the Subscibers preferred language!
Steps to reproduce
- Install and setup symfony_mailer and simplenews (default setup, follow the module instructions)
- Enable the symfony_mailer simplenews override to hand rendering of simplenews to symfony_mailer
- Enable content translation module and setup at least two content languages for your site
- Setup a newsletter list with at least two Subscibers with different preffered language
- Create a node, write some text into the body and set the simplenews issue to the newsletter list.
- Create translations for the node and translate the actual body
- Let symfony_mailer + simplenews deliver your node
⚠️ All Subscribers receive the email in sites default language ⚠️
Problem cause
The problem seems to be that EntityViewBuilder::view() is not provided with a langcode from Email::setBodyEntity(), hence "defaults to the current content language." and this is always the sites default language, cause the cron/spooler (initiating the email deliveries) does not care for the preffered language of individual Subscribers.
Proposed resolution
Add $langcode parameter to EmailInterface::setBodyEntity(...) so an EmailBuilder gets in power to control the rendering language of BodyEntities.
Remaining tasks
User interface changes
API changes
Added optional $langcode parameter to EmailInterface
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3404732-Email_setBodyEntity_in_preRender.patch | 1.07 KB | tomsaw |
| #2 | 3404732-Email_setBodyEntity_support_langcode.patch | 2.21 KB | tomsaw |
Issue fork symfony_mailer-3404732
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
tomsaw commentedComment #3
tomsaw commentedComment #4
tomsaw commentedComment #5
tomsaw commentedComment #6
tomsaw commentedComment #7
tomsaw commentedComment #8
tomsaw commentedComment #9
adamps commentedThanks for the report, well spotted. Your fix is correct, however I have suggestion that I feel is a little simpler.
This module automatically switches the language in
Mailer::doSend(), which is intended to mean that email builders don't have to worry much about language. The switch happens between build() and preRender().Unfortunately,
SimplenewsNewsletterEmailBuildercallssetBodyEntity()inbuild(), which is before the language switch. I think if this line is moved topreRender()(create a new function) then it would then work automatically. Please could you give it a try?Comment #10
tomsaw commentedGot it AdamPS. Sounds much better and I check your proposed solution soon.
Comment #11
tomsaw commentedNice and clean
Comment #12
adamps commentedGreat. Please can you add a comment to explain, something like this "Set the body entity in the pre-render phase to get the right language".
This module has now moved to gitlab testing which works on merge requests instead of patches (which are now deprecated for all Drupal.org). Please can you make a MR?
Comment #13
tomsaw commentedThe translation concept is worth being explained in the Interface above
preRenderdeclaration I would say!Comment #14
tomsaw commentedMR no prob 👍
Comment #16
tomsaw commentedHope the MR works, cause I'm not yet 100% fit with gitlab / drupalcode.org.
Comment #18
adamps commentedGreat thanks
Comment #20
adamps commentedUnfortunately this doesn't work, sorry for the bad advice. The email policy is ignored, we only see the node entity.
The call to $email->setBodyEntity() in preRender() it comes after BodyEmailAdjuster->build() and overwrites it.
Comment #22
adamps commentedI believe we can't fix it yet. However it will be automatically fixed by #3421400: Change to the phases in v2.x.
Comment #23
adamps commentedThis was fixed by #3421400: Change to the phases