Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9501407

Browse files
committed
[Mailer] Fix rendered templates for notifications
1 parent3bcca99 commit9501407

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

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

Lines 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‎

Lines 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+
privatebool$rendered =false;
4344

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

182+
publicfunctionisRendered():bool
183+
{
184+
return$this->rendered;
185+
}
186+
187+
publicfunctionmarkAsRendered():void
188+
{
189+
$this->rendered =true;
190+
}
191+
181192
publicfunctiongetPreparedHeaders():Headers
182193
{
183194
$headers =parent::getPreparedHeaders();
@@ -225,15 +236,17 @@ private function getExceptionAsString(\Throwable|FlattenException $exception): s
225236
*/
226237
publicfunction__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
publicfunction__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‎

Lines 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+
publicfunctionisRendered():bool
71+
{
72+
returnnull ===$this->htmlTemplate &&null ===$this->textTemplate;
73+
}
74+
75+
publicfunctionmarkAsRendered():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‎

Lines 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 ($messageinstanceof TemplatedEmail &&($message->getTextTemplate() ||$message->getHtmlTemplate())) {
79+
if ($messageinstanceof TemplatedEmail &&!$message->isRendered()) {
8080
thrownewLogicException(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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp