Skip to content
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
17 changes: 17 additions & 0 deletions src/Symfony/Bridge/Twig/Mime/NotificationEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ public function getHtmlTemplate(): ?string
return '@email/'.$this->theme.'/notification/body.html.twig';
}

public function context(array $context)
{
$parentContext = [];

foreach ($context as $key => $value) {
if (\array_key_exists($key, $this->context)) {
$this->context[$key] = $value;
} else {
$parentContext[$key] = $value;
}
}

parent::context($parentContext);

return $this;
}

public function getContext(): array
{
return array_merge($this->context, parent::getContext());
Expand Down
50 changes: 50 additions & 0 deletions src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,54 @@ public function testPublicMailSubject()
$headers = $email->getPreparedHeaders();
$this->assertSame('Foo', $headers->get('Subject')->getValue());
}

public function testContext()
{
$email = new NotificationEmail();
$email->context(['some' => 'context']);

$this->assertSame([
'importance' => NotificationEmail::IMPORTANCE_LOW,
'content' => '',
'exception' => false,
'action_text' => null,
'action_url' => null,
'markdown' => false,
'raw' => false,
'footer_text' => 'Notification e-mail sent by Symfony',
'some' => 'context',
], $email->getContext());

$context = $email->getContext();
$context['foo'] = 'bar';
$email->context($context);

$this->assertSame([
'importance' => NotificationEmail::IMPORTANCE_LOW,
'content' => '',
'exception' => false,
'action_text' => null,
'action_url' => null,
'markdown' => false,
'raw' => false,
'footer_text' => 'Notification e-mail sent by Symfony',
'some' => 'context',
'foo' => 'bar',
], $email->getContext());

$email->action('Action Text', 'Action URL');

$this->assertSame([
'importance' => NotificationEmail::IMPORTANCE_LOW,
'content' => '',
'exception' => false,
'action_text' => 'Action Text',
'action_url' => 'Action URL',
'markdown' => false,
'raw' => false,
'footer_text' => 'Notification e-mail sent by Symfony',
'some' => 'context',
'foo' => 'bar',
], $email->getContext());
}
}