You are here

function simplenews_token_replace_subject in Simplenews 3.x

Replaces tokens in a mail subject line.

This is a wrapper to Token::replace() for the email subject.

Parameters

string $text: An HTML string containing replaceable tokens.

array $data: (optional) An array of keyed objects.

array $options: (optional) A keyed array of settings and flags to control the token replacement process.

Return value

string String with tokens replaced.

3 calls to simplenews_token_replace_subject()
MailBuilder::buildCombinedMail in src/Mail/MailBuilder.php
Build subject and body of the subscribe confirmation email.
MailBuilder::buildValidateMail in src/Mail/MailBuilder.php
Build subject and body of the validate email.
MailEntity::getSubject in src/Mail/MailEntity.php
Returns the mail subject.

File

./simplenews.module, line 963
Simplenews node handling, sent email, newsletter block and general hooks.

Code

function simplenews_token_replace_subject($text, array $data = [], array $options = []) {

  // The input string must be escaped in case of special characters like &.
  // The output must remain as markup. The surprising fact is that the Drupal
  // mail system expects to receive markup and automatically decodes it.
  // @see https://www.drupal.org/node/2575791.
  return Markup::create(\Drupal::token()
    ->replace(Html::escape($text), $data, $options));
}