Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ba1bd59

Browse filesBrowse files
committed
[Mailer] Fix rendered templates for notifications
1 parent 3bcca99 commit ba1bd59
Copy full SHA for ba1bd59

File tree

5 files changed

+31
-8
lines changed
Filter options

5 files changed

+31
-8
lines changed

‎src/Symfony/Bridge/Twig/Mime/BodyRenderer.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Mime/BodyRenderer.php
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,13 @@ public function render(Message $message): void
5959

6060
if ($template = $message->getTextTemplate()) {
6161
$message->text($this->twig->render($template, $vars));
62-
$message->textTemplate(null);
6362
}
6463

6564
if ($template = $message->getHtmlTemplate()) {
6665
$message->html($this->twig->render($template, $vars));
67-
$message->htmlTemplate(null);
6866
}
6967

70-
$message->context([]);
68+
$message->markAsRendered();
7169

7270
// if text body is empty, compute one from the HTML body
7371
if (!$message->getTextBody() && null !== $html = $message->getHtmlBody()) {

‎src/Symfony/Bridge/Twig/Mime/NotificationEmail.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Mime/NotificationEmail.php
+15-2Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class NotificationEmail extends TemplatedEmail
4040
'raw' => false,
4141
'footer_text' => 'Notification e-mail sent by Symfony',
4242
];
43+
private bool $rendered = false;
4344

4445
public function __construct(Headers $headers = null, AbstractPart $body = null)
4546
{
@@ -178,6 +179,16 @@ public function getContext(): array
178179
return array_merge($this->context, parent::getContext());
179180
}
180181

182+
public function isRendered(): bool
183+
{
184+
return $this->rendered;
185+
}
186+
187+
public function markAsRendered(): void
188+
{
189+
$this->rendered = true;
190+
}
191+
181192
public function getPreparedHeaders(): Headers
182193
{
183194
$headers = parent::getPreparedHeaders();
@@ -225,15 +236,17 @@ private function getExceptionAsString(\Throwable|FlattenException $exception): s
225236
*/
226237
public function __serialize(): array
227238
{
228-
return [$this->context, $this->theme, parent::__serialize()];
239+
return [$this->context, $this->theme, $this->rendered, parent::__serialize()];
229240
}
230241

231242
/**
232243
* @internal
233244
*/
234245
public function __unserialize(array $data): void
235246
{
236-
if (3 === \count($data)) {
247+
if (4 === \count($data)) {
248+
[$this->context, $this->theme, $this->rendered, $parentData] = $data;
249+
} elseif (3 === \count($data)) {
237250
[$this->context, $this->theme, $parentData] = $data;
238251
} else {
239252
// Backwards compatibility for deserializing data structures that were serialized without the theme

‎src/Symfony/Bridge/Twig/Mime/TemplatedEmail.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Mime/TemplatedEmail.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ public function getContext(): array
6767
return $this->context;
6868
}
6969

70+
public function isRendered(): bool
71+
{
72+
return null === $this->htmlTemplate && null === $this->textTemplate;
73+
}
74+
75+
public function markAsRendered(): void
76+
{
77+
$this->textTemplate = null;
78+
$this->htmlTemplate = null;
79+
$this->context = [];
80+
}
81+
7082
/**
7183
* @internal
7284
*/

‎src/Symfony/Component/Mailer/Transport/AbstractTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/AbstractTransport.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function send(RawMessage $message, Envelope $envelope = null): ?SentMessa
7676
$envelope = $event->getEnvelope();
7777
$message = $event->getMessage();
7878

79-
if ($message instanceof TemplatedEmail && ($message->getTextTemplate() || $message->getHtmlTemplate())) {
79+
if ($message instanceof TemplatedEmail && !$message->isRendered()) {
8080
throw new LogicException(sprintf('You must configure a "%s" when a "%s" instance has a text or HTML template set.', BodyRendererInterface::class, get_debug_type($message)));
8181
}
8282

‎src/Symfony/Component/Mailer/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/composer.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"psr/event-dispatcher": "^1",
2222
"psr/log": "^1|^2|^3",
2323
"symfony/event-dispatcher": "^5.4|^6.0",
24-
"symfony/mime": "^6.2",
24+
"symfony/mime": "^6.2.1",
2525
"symfony/service-contracts": "^1.1|^2|^3"
2626
},
2727
"require-dev": {
@@ -33,7 +33,7 @@
3333
"conflict": {
3434
"symfony/http-kernel": "<5.4",
3535
"symfony/messenger": "<6.2",
36-
"symfony/mime": "<6.2"
36+
"symfony/mime": "<6.2.1"
3737
},
3838
"autoload": {
3939
"psr-4": { "Symfony\\Component\\Mailer\\": "" },

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.