Problem/Motivation
In the past, using Swiftmailer, we used to display the mail subject as headline in the emails, below the title image.
This currently doesn't seem possible using Drupal Symfony Mailer, as the subject isn't passed to the twig files.
Could this be passed as {{ subject }} again in the future? I guess it might not only help us.
Thank you.
Steps to reproduce
Proposed resolution
Pass {{ subject }} to both twig files:
/**
* Implements hook_theme().
*/
function symfony_mailer_theme($existing, $type, $theme, $path) {
return [
'email' => [
'variables' => [
'email' => NULL,
'subject' => NULL,
],
'mail theme' => TRUE,
],
'email_wrap' => [
'variables' => [
'email' => NULL,
'subject' => NULL,
'body' => '',
'is_html' => TRUE,
],
],
];
}
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
anybodyComment #4
anybodyGave this a first shot. If AdamPS is fine with the general approach, we need to add tests. Setting to NR for now to get initial feedback on the request.
Comment #5
anybodyComment #6
adamps commentedThanks for the idea and patch.
I believe the changes to
symfony_mailer_theme()aren't needed. So anyone who wants this could already do it by adding their own preprocess function, containing a single line of code.However it's easy to do in the module also, so I'm open to the idea if there is support. How about if we wait a little and see if anyone else comments asking for it?
Comment #7
thomas.frobieterThe thing is, subject where available in swiftmailer and I guess many sites used this as as heading in the mailtext in addition to the mail subject.
So +1 for the idea, this will make the migration a little easier.
Comment #8
grevil commentedI agree providing the subject would make sense for BC with Swiftmailer and shouldn't need an extra hook, I think. Useful addition for all. Thanks!
Comment #9
adamps commentedGreat then let's do it.
As per #6, please try removing the changes to
symfony_mailer_theme().Comment #10
anybodyThanks @AdamPS, I removed the changes from symfony_mailer_theme(), still I found them helpful to see the available variables.
So we should instead document them in the twig file. I didn't have the time to test it, so let's keep this NW for these final TODOs.
Comment #11
grevil commentedDone
Comment #12
grevil commentedHere is the test output:

With the following code overwritten in the "email-wrap.html.twig":
Comment #13
anybodyPerfect, confirming the manual test. Don't think we need a further automated test here?
Comment #15
adamps commentedGreat thanks
Comment #16
anybodyThank YOU @AdamPS! Cool to see this merged :) Helps me a lot with many projects.
Comment #17
grevil commentedThanks @AdamPS!