function update_mail

Same name in other branches
  1. 7.x modules/update/update.module \update_mail()
  2. 8.9.x core/modules/update/update.module \update_mail()
  3. 10 core/modules/update/update.module \update_mail()

Implements hook_mail().

Constructs the email notification message when the site is out of date.

See also

\Drupal\Core\Mail\MailManagerInterface::mail()

_update_cron_notify()

_update_message_text()

\Drupal\update\UpdateManagerInterface

File

core/modules/update/update.module, line 397

Code

function update_mail($key, &$message, $params) {
    $langcode = $message['langcode'];
    $language = \Drupal::languageManager()->getLanguage($langcode);
    $message['subject'] .= t('New release(s) available for @site_name', [
        '@site_name' => \Drupal::config('system.site')->get('name'),
    ], [
        'langcode' => $langcode,
    ]);
    foreach ($params as $msg_type => $msg_reason) {
        $message['body'][] = _update_message_text($msg_type, $msg_reason, $langcode);
    }
    $message['body'][] = t('See the available updates page for more information:', [], [
        'langcode' => $langcode,
    ]) . "\n" . Url::fromRoute('update.status', [], [
        'absolute' => TRUE,
        'language' => $language,
    ])->toString();
    if (_update_manager_access()) {
        $message['body'][] = t('You can automatically install your missing updates using the Update manager:', [], [
            'langcode' => $langcode,
        ]) . "\n" . Url::fromRoute('update.report_update', [], [
            'absolute' => TRUE,
            'language' => $language,
        ])->toString();
    }
    $settings_url = Url::fromRoute('update.settings', [], [
        'absolute' => TRUE,
    ])->toString();
    if (\Drupal::config('update.settings')->get('notification.threshold') == 'all') {
        $message['body'][] = t('Your site is currently configured to send these emails when any updates are available. To get notified only for security updates, @url.', [
            '@url' => $settings_url,
        ]);
    }
    else {
        $message['body'][] = t('Your site is currently configured to send these emails only when security updates are available. To get notified for any available updates, @url.', [
            '@url' => $settings_url,
        ]);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.