8000 [twig-bridge] NotificationEmail action not being applied · Issue #53655 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[twig-bridge] NotificationEmail action not being applied #53655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fyrye opened this issue Jan 28, 2024 · 1 comment
Closed

[twig-bridge] NotificationEmail action not being applied #53655

fyrye opened this issue Jan 28, 2024 · 1 comment

Comments

@fyrye
Copy link
fyrye commented Jan 28, 2024

Symfony version(s) affected

4.4, 5,4, 6.4, 7.0

Description

When attempting to add to the context of the NotificationEmail using getContext() and calling NotificationEmail::action(...) the action context values are never set due to the usage of return array_merge($this->context, parent::getContext()) and calling ::context() is applied to the parent TemplatedEmail.

How to reproduce

$notification = new NotificationEmail();
$notification->context(['some' => 'context']);
/**
 * ... do other things like pass to a handler/dispatcher/listener 
 */
$context = $notification->getContext();
$context['foo'] = 'bar';
$notification->context($context);
$notification->action('Action Text', 'Action URL');

dump($notification->getContext());

Result

[
    'some' => 'context',
    'foo' => 'bar',
    'action_text' => null,
    'action_url' => null,
]

Generic Example of the issue: https://3v4l.org/InQVh

Possible Solution

Workaround

Call NotificationEmail::action() prior to NotificationEmail::getContext().

$notification->action('Action Text', 'Action URL');
$context = $notification->getContext();
$context['foo'] = 'bar';
$notification->context($context);
// ...

Additional Context

Discovered when attempting to make a notification handler that would add to the email context and call the NotificationEmail::action(). When dumping the object it showed the action context keys as being set, but the actions were not in the generated content, which was unexpected behavior.

dump($notification);

Result

image

@fyrye fyrye added the Bug label Jan 28, 2024
@fyrye fyrye changed the title twig-bridge NotificationEmail action not being applied [twig-bridge] NotificationEmail action not being applied Jan 28, 2024
@xabbuh
Copy link
Member
xabbuh commented Jan 29, 2024

Can you check if #53663 fixes your issue?

nicolas-grekas added a commit that referenced this issue Jan 29, 2024
…tionEmail on writes (xabbuh)

This PR was merged into the 5.4 branch.

Discussion
----------

[TwigBridge] separate child and parent context in NotificationEmail on writes

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #53655
| License       | MIT

Commits
-------

78bbfb0 separate child and parent context in NotificationEmail on writes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0