Skip to content

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

@fyrye

Description

@fyrye

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy