10000 Fix the notification email theme for asynchronously dispatched emails by krisbuist · Pull Request #48092 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix the notification email theme for asynchronously dispatched emails #48092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix the notification email theme for asynchronously dispatched emails
When the `\Symfony\Component\Mailer\Messenger\SendEmailMessage` is dispatched asynchronously, the email message is serialised and unserialised. The theme that was set on the `NotificationEmail` was not included in the serialisation, causing the
value to return back to the default afte
10000
r deserialisation.
  • Loading branch information
krisbuist committed Nov 3, 2022
commit 4b843d1eeae5e3b8b62affbcc08fa9e9acf72b0a
9 changes: 7 additions & 2 deletions src/Symfony/Bridge/Twig/Mime/NotificationEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,20 @@ private function getExceptionAsString($exception): string
*/
public function __serialize(): array
{
return [$this->context, parent::__serialize()];
return [$this->context, $this->theme, parent::__serialize()];
}

/**
* @internal
*/
public function __unserialize(array $data): void
{
[$this->context, $parentData] = $data;
if (3 === \count($data)) {
[$this->context, $this->theme, $parentData] = $data;
} else {
// Backwards compatibility for deserializing data structures that were serialized without the theme
[$this->context, $parentData] = $data;
}

parent::__unserialize($parentData);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php
38DE
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function testSerialize()
->importance(NotificationEmail::IMPORTANCE_HIGH)
->action('Bar', 'http://example.com/')
->context(['a' => 'b'])
->theme('example')
));
$this->assertEquals([
'importance' => NotificationEmail::IMPORTANCE_HIGH,
Expand All @@ -57,6 +58,8 @@ public function testSerialize()
'raw' => true,
'a' => 'b',
], $email->getContext());

$this->assertSame('@email/example/notification/body.html.twig', $email->getHtmlTemplate());
}

public function testTheme()
Expand Down
0