You are here

protected function DevelMailLog::replacePlaceholders in Devel 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Mail/DevelMailLog.php \Drupal\devel\Plugin\Mail\DevelMailLog::replacePlaceholders()
  2. 8 src/Plugin/Mail/DevelMailLog.php \Drupal\devel\Plugin\Mail\DevelMailLog::replacePlaceholders()
  3. 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 156

Class

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

Namespace

Drupal\devel\Plugin\Mail

Code

protected function replacePlaceholders($filename, array $message) {
  $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);
}