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

CommentFileSizeAuthor
#12 2023-06-19 11_30_46-MailHog.png9.28 KBgrevil
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

Anybody created an issue. See original summary.

anybody’s picture

Title: Pass mail subject to the theme » Pass mail subject to the twig files
Issue summary: View changes

anybody’s picture

Status: Active » Needs review
Issue tags: +Needs tests

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

anybody’s picture

Title: Pass mail subject to the twig files » Pass mail subject to the twig files as variable
adamps’s picture

Thanks 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?

thomas.frobieter’s picture

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

grevil’s picture

I 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!

adamps’s picture

Status: Needs review » Needs work

Great then let's do it.

As per #6, please try removing the changes to symfony_mailer_theme().

anybody’s picture

Thanks @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.

grevil’s picture

Status: Needs work » Needs review

Done

grevil’s picture

StatusFileSize
new9.28 KB

Here is the test output:
screenshot

With the following code overwritten in the "email-wrap.html.twig":

          Subject: "<strong>{{ subject }}</strong>"
          <br />
          Body: "{{ body }}"
anybody’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Perfect, confirming the manual test. Don't think we need a further automated test here?

  • AdamPS committed 33092e70 on 1.x authored by Anybody
    Issue #3366238 by Anybody, Grevil: Pass mail subject to the twig files...
adamps’s picture

Status: Reviewed & tested by the community » Fixed

Great thanks

anybody’s picture

Thank YOU @AdamPS! Cool to see this merged :) Helps me a lot with many projects.

grevil’s picture

Thanks @AdamPS!

Status: Fixed » Closed (fixed)

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