protected function Pet::sendSingleMail in Previewable email templates 8.3
Send PET to single recipient.
Parameters
string $recipient: Recipient email address.
array $context: Context items to be used for token substitutions.
Return value
array Result value of MailManager::mail().
1 call to Pet::sendSingleMail()
- Pet::sendMail in src/
Entity/ Pet.php - Send PET to one or more recipients.
File
- src/
Entity/ Pet.php, line 661
Class
- Pet
- Defines the pet entity.
Namespace
Drupal\pet\EntityCode
protected function sendSingleMail($recipient, array $context) {
$langcode = \Drupal::languageManager()
->getDefaultLanguage()
->getId();
$params = [];
$params['context'] = $context;
$user = user_load_by_mail($recipient);
if ($user) {
// Get user preferred language.
$preferred_admin_langcode = $user
->getPreferredLangcode();
$langcode = $preferred_admin_langcode ?: $langcode;
$params['context']['uid'] = $user
->id();
}
else {
$params['context']['uid'] = 0;
}
if ($this
->hasTranslation($langcode)) {
$params['pet'] = $this
->getTranslation($langcode);
}
else {
// @todo: see if we can get default translation explicitly.
$params['pet'] = $this;
}
$reply = $this
->getReplyTo() ?: \Drupal::config('system.site')
->get('mail');
// @see MailManager::mail($module, $key, $to, $langcode, $params = [], $reply = NULL, $send = TRUE)
$message = \Drupal::service('plugin.manager.mail')
->mail('pet', $this
->id(), $recipient, $langcode, $params, $reply);
if ($message['result']) {
$this
->log("'@title' send to %recipient", [
'@title' => $this
->getTitle(),
'%recipient' => $recipient,
]);
}
else {
$this
->log("Could not send '@title' to %recipient", [
'@title' => $this
->getTitle(),
'%recipient' => $recipient,
]);
}
return $message;
}