Description
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);