diff --git a/src/Symfony/Bridge/Twig/CHANGELOG.md b/src/Symfony/Bridge/Twig/CHANGELOG.md index b2d25bce4f..90bc898617 100644 --- a/src/Symfony/Bridge/Twig/CHANGELOG.md +++ b/src/Symfony/Bridge/Twig/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +5.3 +----- + +* Add a new `markAsPublic` method on `NotificationEmail` to change the `importance` context option to null after creation + 5.3.0 ----- diff --git a/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php b/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php index a91ce2c8b8..2058b8e67d 100644 --- a/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php +++ b/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php @@ -64,12 +64,19 @@ class NotificationEmail extends TemplatedEmail public static function asPublicEmail(Headers $headers = null, AbstractPart $body = null): self { $email = new static($headers, $body); - $email->context['importance'] = null; - $email->context['footer_text'] = null; + $email->markAsPublic(); return $email; } + public function markAsPublic(): self + { + $this->context['importance'] = null; + $this->context['footer_text'] = null; + + return $this; + } + /** * @return $this */ diff --git a/src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php b/src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php index 81876a4229..6eed243690 100644 --- a/src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php @@ -85,6 +85,25 @@ class NotificationEmailTest extends TestCase 'a' => 'b', 'footer_text' => null, ], $email->getContext()); + + $email = (new NotificationEmail()) + ->markAsPublic() + ->markdown('Foo') + ->action('Bar', 'http://example.com/') + ->context(['a' => 'b']) + ; + + $this->assertEquals([ + 'importance' => null, + 'content' => 'Foo', + 'exception' => false, + 'action_text' => 'Bar', + 'action_url' => 'http://example.com/', + 'markdown' => true, + 'raw' => false, + 'a' => 'b', + 'footer_text' => null, + ], $email->getContext()); } public function testPublicMailSubject() @@ -92,5 +111,9 @@ class NotificationEmailTest extends TestCase $email = NotificationEmail::asPublicEmail()->from('me@example.com')->subject('Foo'); $headers = $email->getPreparedHeaders(); $this->assertSame('Foo', $headers->get('Subject')->getValue()); + + $email = (new NotificationEmail())->markAsPublic()->from('me@example.com')->subject('Foo'); + $headers = $email->getPreparedHeaders(); + $this->assertSame('Foo', $headers->get('Subject')->getValue()); } }