You are here

protected function DevelMailLog::replacePlaceholders in Devel 8

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

$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 155

Class

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

Namespace

Drupal\devel\Plugin\Mail

Code

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