function EmailAction::execute
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Action/Plugin/Action/EmailAction.php \Drupal\Core\Action\Plugin\Action\EmailAction::execute()
- 10 core/lib/Drupal/Core/Action/Plugin/Action/EmailAction.php \Drupal\Core\Action\Plugin\Action\EmailAction::execute()
- 11.x core/lib/Drupal/Core/Action/Plugin/Action/EmailAction.php \Drupal\Core\Action\Plugin\Action\EmailAction::execute()
Overrides ExecutableInterface::execute
File
-
core/
lib/ Drupal/ Core/ Action/ Plugin/ Action/ EmailAction.php, line 122
Class
- EmailAction
- Sends an email message.
Namespace
Drupal\Core\Action\Plugin\ActionCode
public function execute($entity = NULL) {
if (empty($this->configuration['node'])) {
$this->configuration['node'] = $entity;
}
$recipient = PlainTextOutput::renderFromHtml($this->token
->replace($this->configuration['recipient'], $this->configuration));
// If the recipient is a registered user with a language preference, use
// the recipient's preferred language. Otherwise, use the system default
// language.
$recipient_accounts = $this->storage
->loadByProperties([
'mail' => $recipient,
]);
$recipient_account = reset($recipient_accounts);
if ($recipient_account) {
$langcode = $recipient_account->getPreferredLangcode();
}
else {
$langcode = $this->languageManager
->getDefaultLanguage()
->getId();
}
$params = [
'context' => $this->configuration,
];
$message = $this->mailManager
->mail('system', 'action_send_email', $recipient, $langcode, $params);
// Error logging is handled by \Drupal\Core\Mail\MailManager::mail().
if ($message['result']) {
$this->logger
->notice('Sent email to %recipient', [
'%recipient' => $recipient,
]);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.