Skip to content
Snippets Groups Projects

Issue #3252427: Provide token support for email addresses used by SMTP config

1 file
+ 63
0
Compare changes
  • Side-by-side
  • Inline
smtp.tokens.inc 0 → 100644
+ 63
0
<?php
/**
* @file
* Builds placeholder replacement tokens for smtp data.
*
* This file handles tokens for the smtp tokens.
*/
/**
* Implements hook_token_info().
*/
function smtp_token_info(): array {
$types['smtp'] = [
'name' => t("SMTP data"),
'description' => t("Tokens for smtp settings."),
];
$smtp['from'] = [
'name' => t("E-mail from address"),
'description' => t("The e-mail address that all e-mails will be from."),
];
$smtp['fromname'] = [
'name' => t("E-mail from name"),
'description' => t("The name that all e-mails will be from."),
];
$smtp['username'] = [
'name' => t("Username"),
'description' => t("SMTP Username."),
];
return [
'types' => $types,
'tokens' => [
'smtp' => $smtp,
],
];
}
/**
* Implements hook_tokens().
*/
function smtp_tokens($type, $tokens): array {
$replacements = [];
if ($type === 'smtp') {
$config = \Drupal::config('smtp.settings');
foreach ($tokens as $name => $original) {
switch ($name) {
case 'from':
$replacements[$original] = $config->get('smtp_from');
break;
case 'fromname':
$replacements[$original] = $config->get('smtp_fromname');
break;
case 'username':
$replacements[$original] = $config->get('smtp_username');
break;
}
}
}
return $replacements;
}
Loading