function DevelMailLog::replacePlaceholders

Same name in other branches
  1. 4.x src/Plugin/Mail/DevelMailLog.php \Drupal\devel\Plugin\Mail\DevelMailLog::replacePlaceholders()

Replaces placeholders with sanitized values in a string.

Parameters

string $filename: The string that contains the placeholders. The following placeholders are considered in the replacement:

  • %to: replaced by the email recipient value.
  • %subject: replaced by the email subject value.
  • %datetime: replaced by the current datetime in 'y-m-d_his' format.

array $message: A message array, as described in hook_mail_alter().

Return value

string The formatted string.

1 call to DevelMailLog::replacePlaceholders()
DevelMailLog::mail in src/Plugin/Mail/DevelMailLog.php
Sends a message composed by \Drupal\Core\Mail\MailManagerInterface->mail().

File

src/Plugin/Mail/DevelMailLog.php, line 148

Class

DevelMailLog
Defines a mail backend that saves emails as temporary files.

Namespace

Drupal\devel\Plugin\Mail

Code

protected function replacePlaceholders(string $filename, array $message) : string {
    $tokens = [
        '%to' => $message['to'],
        '%subject' => $message['subject'],
        '%datetime' => date('y-m-d_his'),
    ];
    $filename = str_replace(array_keys($tokens), array_values($tokens), $filename);
    return preg_replace('/[^a-zA-Z0-9_\\-\\.@]/', '_', $filename) ?? '';
}