Description
Currently, the [code] and [length] placeholders are only replaced in the email body when sending the OTP email. As a result, if these placeholders are used in the email subject, they remain unchanged and appear literally in the subject line.

This pull request applies the same token replacement logic to the email subject as already implemented for the email body. This ensures that [code] and [length] can be used consistently in both the subject and the body of the authentication email.

Before
[code] and [length] are replaced in the body only.
If used in the subject, the placeholders are not replaced.

After
[code] and [length] are replaced in both the subject and the body, providing consistent behavior.

Change introduced

// Replace tokens in the email subject.
$subject = str_replace($search, $replace, $this->emailSetting['subject']);

$this->message = [
  'subject' => $subject,
  'langcode' => $this->langCode,
  'body' => $body,
];

This mirrors the existing replacement logic used for the email body and allows site administrators to include the authentication code directly in the email subject if desired.

Benefits

Consistent token behavior between subject and body
More flexibility for administrators configuring authentication emails

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

amdcm created an issue. See original summary.

amdcm’s picture

Title: Add token in email subject » Replace tokens in email subject
Issue summary: View changes
amdcm’s picture

Issue summary: View changes
Status: Needs work » Needs review