class MailHandler
Same name in this branch
- 11.x core/modules/contact/src/MailHandler.php \Drupal\contact\MailHandler
Same name and namespace in other branches
- 10 core/modules/contact/src/MailHandler.php \Drupal\contact\MailHandler
- 9 core/modules/contact/src/MailHandler.php \Drupal\contact\MailHandler
- 8.9.x core/modules/contact/src/MailHandler.php \Drupal\contact\MailHandler
- main core/modules/contact/src/MailHandler.php \Drupal\contact\MailHandler
- main core/modules/update/src/MailHandler.php \Drupal\update\MailHandler
A service to handle assembly and dispatch of Update Status mail messages.
@internal
Hierarchy
- class \Drupal\update\MailHandler
Expanded class hierarchy of MailHandler
1 file declares its use of MailHandler
- UpdateCronHooks.php in core/
modules/ update/ src/ Hook/ UpdateCronHooks.php
File
-
core/
modules/ update/ src/ MailHandler.php, line 18
Namespace
Drupal\updateView source
class MailHandler {
public function __construct(protected readonly EntityTypeManagerInterface $entityTypeManager, protected readonly LanguageManagerInterface $languageManager, protected readonly TimeInterface $time, #[AutowireServiceClosure('plugin.manager.mail')] protected readonly \Closure $mailManager) {
}
/**
* Sends update notification mails to a list of recipients.
*
* @param string[] $recipients
* A list of recipient mail addresses.
* @param array{'core'?: int, 'contrib'?: int} $items
* The update status entries for core and contrib projects. Allowed values
* are defined as constants on UpdateManagerInterface.
*
* @return bool
* TRUE if any email notifications were sent, otherwise FALSE.
*
* @see \Drupal\update\UpdateManagerInterface
*/
public function sendUpdateNotifications(array $recipients, array $items) : bool {
$results = [];
$default_langcode = $this->languageManager
->getDefaultLanguage()
->getId();
$storage = $this->entityTypeManager
->getStorage('user');
$accounts_by_email = [];
foreach ($storage->loadByProperties([
'mail' => $recipients,
]) as $account) {
assert($account instanceof AccountInterface);
$accounts_by_email[$account->getEmail()] = $account;
}
foreach ($recipients as $recipient) {
// If the recipient is a registered user with a language preference, use
// the recipient's preferred language. Otherwise, use the system default
// language.
$recipient_account = $accounts_by_email[$recipient] ?? NULL;
$langcode = $recipient_account ? $recipient_account->getPreferredLangcode() : $default_langcode;
$message = ($this->mailManager)()
->mail('update', 'status_notify', $recipient, $langcode, $items);
$results[] = $message['result'] ?? NULL;
}
return count(array_filter($results)) > 0;
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| MailHandler::sendUpdateNotifications | public | function | Sends update notification mails to a list of recipients. |
| MailHandler::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.