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

  1. Install and setup symfony_mailer and simplenews (default setup, follow the module instructions)
  2. Enable the symfony_mailer simplenews override to hand rendering of simplenews to symfony_mailer
  3. Enable content translation module and setup at least two content languages for your site
  4. Setup a newsletter list with at least two Subscibers with different preffered language
  5. Create a node, write some text into the body and set the simplenews issue to the newsletter list.
  6. Create translations for the node and translate the actual body
  7. 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

Command icon 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

TomSaw created an issue. See original summary.

tomsaw’s picture

tomsaw’s picture

Issue summary: View changes
tomsaw’s picture

Issue summary: View changes
tomsaw’s picture

Issue summary: View changes
tomsaw’s picture

Issue summary: View changes
tomsaw’s picture

Issue summary: View changes
tomsaw’s picture

Title: Simplenews node issue not rendered in Subcribers preffered language » Simplenews node issue should be rendered in Subcribers preffered language
adamps’s picture

Status: Needs review » Needs work

Thanks 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, SimplenewsNewsletterEmailBuilder calls setBodyEntity() in build(), which is before the language switch. I think if this line is moved to preRender() (create a new function) then it would then work automatically. Please could you give it a try?

tomsaw’s picture

Got it AdamPS. Sounds much better and I check your proposed solution soon.

tomsaw’s picture

Nice and clean

adamps’s picture

Great. 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?

tomsaw’s picture

The translation concept is worth being explained in the Interface above preRender declaration I would say!

tomsaw’s picture

MR no prob 👍

tomsaw’s picture

Status: Needs work » Reviewed & tested by the community

Hope the MR works, cause I'm not yet 100% fit with gitlab / drupalcode.org.

  • AdamPS committed 1d6a54ea on 1.x authored by TomSaw
    Issue #3404732 by TomSaw: Simplenews node issue should be rendered in...
adamps’s picture

Status: Reviewed & tested by the community » Fixed

Great thanks

Status: Fixed » Closed (fixed)

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

adamps’s picture

Status: Closed (fixed) » Needs work

Unfortunately 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.

  • AdamPS committed 8005ff7f on 1.x
    Revert "Issue #3404732 by TomSaw: Simplenews node issue should be...
adamps’s picture

I believe we can't fix it yet. However it will be automatically fixed by #3421400: Change to the phases in v2.x.

adamps’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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