Unable to use inline styles when tokens are used in a message (patch provided)

Created on 20 November 2020, over 4 years ago
Updated 28 July 2023, over 1 year ago

Problem/Motivation

Inline styles (e.g : style="color:#2F2E2E;") are stripped when using tokens in message body.

Steps to reproduce

  • Install Message and Message notify modules
  • Create a message template with one field for the subject, one field for the body and enable related display modes
  • Insert a token (any token would do) in the body
  • Add some html tags with inline styles
  • Add code to generate the message and send it via message notify (the problem is probably there without message notify)

With tokens : inline styles are stripped / without tokens inline styles are still there.

Proposed resolution

The function processTokens in Message.php contains :

foreach ($output as $key => $value) {
      $output[$key] = \Drupal::token()
        ->replace($value, ['message' => $this], $options);
    }

The variable $value is a Markup object and the replace function expect a string and return a string if there is a token to replace. Therefore, the code execution deal with a string type instead of a Markup object. The string is then filtered by the render() function and inline styles are stripped. With a Markup object, inline style are still there.

We can change the code to make sure we always have a Markup object here.

Remaining tasks

Review provided patch.

πŸ› Bug report
Status

Needs review

Version

1.1

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia GuillaumeG

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.

Production build 0.71.5 2024