Improvements to token/variable replacement

Created on 10 June 2025, 2 days ago

Problem/Motivation

  1. Bug: missing escaping HTML before replacing variables in the subject
  2. Bug: token browser is missing for Verify emails (where the only token data is the global site)
  3. Feature: we'd like to add replacement to other fields, especially the plain text body
  4. Task: the current method is inconsistent. Token replacement happens in TokenProcessor, variable replacement of the body in BodyEmailAdjuster and variable replacement of the subject in Email.

Proposed resolution

  1. Extend TokenProcessor also to replace variables, rename it to ReplacementProcessor, and add it to all emails. Use parameters token_data and token_options to control the token replacement.
  2. The metadata from the Mailer attribute includes a value token_types so automatically use this to set the token_data parameter.
  3. Add HTML escaping before replacing variables if the value is plain text.

Remaining tasks

User interface changes

API changes

Affects Mailer implementations that replace tokens.

  1. Remove all code relating to TokenTrait (1.x) or TokenProcessor (earlier version of 2.x).
  2. Use $email->setParam('token_options') if needed to set options

Data model changes

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom adamps

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

Comments & Activities

Production build 0.71.5 2024