Provide a template to customize the content of the notification mail

Created on 17 November 2022, about 2 years ago
Updated 15 September 2023, over 1 year ago

Problem/Motivation

We should provide a template to customize the content of the notification emails. It is a better approach than to rely on customizing the swiftmailer, since we might not want to depend on swiftmailer in the future and usually I prefer to have one global swiftmailer template and customize it's content in separate templates.

We should pass all relevant data such as the product variation (currently not available at all) and the message to that template.

One example is the commerce_order_receipt theme/template: https://git.drupalcode.org/project/commerce/-/blob/8.x-2.x/modules/order...

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡­Switzerland Lukas von Blarer

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Pipeline finished with Skipped
    11 days ago
    #362114
  • πŸ‡ΈπŸ‡°Slovakia poker10

    Thanks for reporting and working on this. I think this is a useful feature.

    Updated the code in the MR:
    - moved the logic from the .module file to the CommerceStockNotifyQueue::processItem()
    - removed static call to Drupal::service()
    - kept the original parameter names for BC
    - added DeprecationHelper to handle renderPlain deprecation
    - removed the language fix which landed in another issue

    Merging this to the 8.x-1.x now. Further improvements can be made if needed in follow-ups. Thanks!

  • πŸ‡ΈπŸ‡°Slovakia poker10

    Need to say, that previously, it was possible to send non-filtered HTML in the $message variable directly to the email body (which is not good from the security perspective). After this commit, the variable is filtered by twig (which is not good for BC reason). We cannot use Xss::filter() or any other filtering because some sites could have a whole HTML pages in the field HTML body field (including styles, attributes, various HTML tags, ...), so it would not help much regarding BC. It seems like that any filtering option will have a potential to break the "unlimited" options provided until this was committed.

    I am not sure how extensively this HTML options were used, but I think there are two options now:

    1. Keep it filtered by default (as it is now) and force existing sites to convert the field HTML to the twig (which is the most secure way) or to override the template and use the |raw filter (the fastest way).

    2. Mark the Administer Commerce stock notifications permission as restricted and allow |raw filter on the $message variable in the default twig template. That is not a best solution, but this will preserve all options.

    Will wait for some opinions from sites using the module. Thanks.

Production build 0.71.5 2024