You are here

function purge_users_send_notification_email in Auto Purge Users 8.3

Same name and namespace in other branches
  1. 8 purge_users.module \purge_users_send_notification_email()
  2. 8.2 purge_users.module \purge_users_send_notification_email()

Send notification email.

2 calls to purge_users_send_notification_email()
UserManagementService::notifyUser in src/Services/UserManagementService.php
Sends a user notification before cancel and anonymize it.
UserManagementService::purgeUser in src/Services/UserManagementService.php
Cancel a user and anonymize it.

File

./purge_users.module, line 321
Purge users module file.

Code

function purge_users_send_notification_email($account, $op = 'user_deletion') {

  // Email to be sent to this Email ID.
  $mailManager = \Drupal::service('plugin.manager.mail');
  $module = 'purge_users';
  $key = 'delete_users';
  $to = $account
    ->get('mail')->value;
  $config = \Drupal::config('purge_users.settings');
  $message = $config
    ->get('inactive_user_notify_text');
  $subject = $config
    ->get('inactive_user_notify_subject');
  if ($op == 'notification_users') {
    $key = 'cancel_users';
    $subject = $config
      ->get('user_before_deletion_subject');
    $message = $config
      ->get('user_before_deletion_text');
  }
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler
    ->moduleExists('token')) {
    $token_service = \Drupal::token();
    $message = $token_service
      ->replace($message, [
      'user' => $account,
    ]);
  }
  $params = [
    'subject' => $subject,
    'body' => $message,
  ];
  $langcode = $account
    ->getPreferredLangcode();
  $send = TRUE;
  $mailManager
    ->mail($module, $key, $to, $langcode, $params, NULL, $send);
}