8000 feature #40448 [twig-bridge] Allow NotificationEmail to be marked as … · symfony/symfony@136e54c · GitHub
[go: up one dir, main page]

Skip to content

Commit 136e54c

Browse files
committed
feature #40448 [twig-bridge] Allow NotificationEmail to be marked as public (maxailloud)
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [twig-bridge] Allow NotificationEmail to be marked as public | Q | A | ------------- | --- | Branch? | 5.x for features | Bug fix? |no | New feature? | yes | Deprecations? |no | Tickets | Fix #37879 | License | MIT | Doc PR | - Closes #37879 `NotificationEmail` can be created public from the `asPublicEmail` method in any context but with the Notifier component. In this case it is created by it as not public and therefore displays the importance in the subject of the email. For end users, aka not admin, the importance in the subject's email is not necessary. This PR will allow if needed to set a `NotificationEmail` as public even after being created, wherever it was created. I am not sure how to handle the version in the changelog. For the tests I don't know what's the policy so I just added a new case in each test case. Commits ------- 8f753d2 [twig-bridge] Allow NotificationEmail to be marked as public
2 parents 7f65a27 + 8f753d2 commit 136e54c

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/Symfony/Bridge/Twig/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.3
5+
-----
6+
7+
* Add a new `markAsPublic` method on `NotificationEmail` to change the `importance` context option to null after creation
8+
49
5.3.0
510
-----
611

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,19 @@ public function __construct(Headers $headers = null, AbstractPart $body = null)
6464
public static function asPublicEmail(Headers $headers = null, AbstractPart $body = null): self
6565
{
6666
$email = new static($headers, $body);
67-
$email->context['importance'] = null;
68-
$email->context['footer_text'] = null;
67+
$email->markAsPublic();
6968

7069
return $email;
7170
}
7271

72+
public function markAsPublic(): self
73+
{
74+
$this->context['importance'] = null;
75+
$this->context['footer_text'] = null;
76+
77+
return $this;
78+
}
79+
7380
/**
7481
* @return $this
7582
*/

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,35 @@ public function testPublicMail()
8585
'a' => 'b',
8686
'footer_text' => null,
8787
], $email->getContext());
88+
89+
$email = (new NotificationEmail())
90+
->markAsPublic()
91+
->markdown('Foo')
92+
->action('Bar', 'http://example.com/')
93+
->context(['a' => 'b'])
94+
;
95+
96+
$this->assertEquals([
97+
'importance' => null,
98+
'content' => 'Foo',
99+
'exception' => false,
100+
'action_text' => 'Bar',
101+
'action_url' => 'http://example.com/',
102+
'markdown' => true,
103+
'raw' => false,
104+
'a' => 'b',
105+
'footer_text' => null,
106+
], $email->getContext());
88107
}
89108

90109
public function testPublicMailSubject()
91110
{
92111
$email = NotificationEmail::asPublicEmail()->from('me@example.com')->subject('Foo');
93112
$headers = $email->getPreparedHeaders();
94113
$this->assertSame('Foo', $headers->get('Subject')->getValue());
114+
115+
$email = (new NotificationEmail())->markAsPublic()->from('me@example.com')->subject('Foo');
116+
$headers = $email->getPreparedHeaders();
117+
$this->assertSame('Foo', $headers->get('Subject')->getValue());
95118
}
96119
}

0 commit comments

Comments
 (0)
0