You are here

function role_watchdog_notify in Role Watchdog 8

Helper function to save entity.

Parameters

$role_message:

$roles_changed:

$account_id:

2 calls to role_watchdog_notify()
role_watchdog_user_insert in ./role_watchdog.module
Implements hook_ENTITY_TYPE_insert().
role_watchdog_user_update in ./role_watchdog.module
Implements hook_ENTITY_TYPE_update().

File

./role_watchdog.module, line 125
Contains role_watchdog.module.

Code

function role_watchdog_notify($role_message, $roles_changed, $account_id) {
  $role_watchdog_config = \Drupal::config('role_watchdog.settings');
  $mail_manager = \Drupal::service('plugin.manager.mail');
  $langcode = \Drupal::currentUser()
    ->getPreferredLangcode();
  $params['message'] = t("Roles changed for User ID @account_id. @role_message : @roles_changed", [
    '@account_id' => $account_id,
    '@role_message' => $role_message,
    '@roles_changed' => implode(',', $roles_changed),
  ]);
  $notify = $mail_manager
    ->mail('role_watchdog', 'notification', $role_watchdog_config
    ->get('role_watchdog_notify_email'), $langcode, $params, NULL, 'TRUE');
  if ($notify['result'] !== TRUE) {
    \Drupal::logger('role_watchdog')
      ->warning('Error sending notification email for Role Watchdog.');
  }
  else {
    \Drupal::logger('role_watchdog')
      ->notice('Email notification for Role Watchdog sent.');
  }
}