8000 separate child and parent context in NotificationEmail on writes · symfony/symfony@78bbfb0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 78bbfb0

Browse files
xabbuhnicolas-grekas
authored andcommitted
separate child and parent context in NotificationEmail on writes
1 parent 4eb23d8 commit 78bbfb0

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,23 @@ public function getHtmlTemplate(): ?string
178178
return '@email/'.$this->theme.'/notification/body.html.twig';
179179
}
180180

181+
public function context(array $context)
182+
{
183+
$parentContext = [];
184+
185+
foreach ($context as $key => $value) {
186+
if (\array_key_exists($key, $this->context)) {
187+
$this->context[$key] = $value;
188+
} else {
189+
$parentContext[$key] = $value;
190+
}
191+
}
192+
193+
parent::context($parentContext);
194+
195+
return $this;
196+
}
197+
181198
public function getContext(): array
182199
{
183200
return array_merge($this->context, parent::getContext());

src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,54 @@ public function testPublicMailSubject()
128128
$headers = $email->getPreparedHeaders();
129129
$this->assertSame('Foo', $headers->get('Subject')->getValue());
130130
}
131+
132+
public function testContext()
133+
{
134+
$email = new NotificationEmail();
135+
$email->context(['some' => 'context']);
136+
137+
$this->assertSame([
138+
'importance' => NotificationEmail::IMPORTANCE_LOW,
139+
'content' => '',
140+
'exception' => false,
141+
'action_text' => null,
142+
'action_url' => null,
143+
'markdown' => false,
144+
'raw' => false,
145+
'footer_text' => 'Notification e-mail sent by Symfony',
146+
'some' => 'context',
147+
], $email->getContext());
148+
149+
$context = $email->getContext();
150+
$context['foo'] = 'bar';
151+
$email->context($context);
152+
153+
$this->assertSame([
154+
'importance' => NotificationEmail::IMPORTANCE_LOW,
155+
'content' => '',
156+
'exception' => false,
157+
'action_text' => null,
158+
'action_url' => null,
159+
'markdown' => false,
160+
'raw' => false,
161+
'footer_text' => 'Notification e-mail sent by Symfony',
162+
'some' => 'context',
163+
'foo' => 'bar',
164+
], $email->getContext());
165+
166+
$email->action('Action Text', 'Action URL');
167+
168+
$this->assertSame([
169+
'importance' => NotificationEmail::IMPORTANCE_LOW,
170+
'content' => '',
171+
'exception' => false,
172+
'action_text' => 'Action Text',
173+
'action_url' => 'Action URL',
174+
'markdown' => false,
175+
'raw' => false,
176+
'footer_text' => 'Notification e-mail sent by Symfony',
177+
'some' => 'context',
178+
'foo' => 'bar',
179+
], $email->getContext());
180+
}
131181
}

0 commit comments

Comments
 (0)
0