You are here

function role_watchdog_user_update in Role Watchdog 8

Implements hook_ENTITY_TYPE_update().

File

./role_watchdog.module, line 32
Contains role_watchdog.module.

Code

function role_watchdog_user_update(EntityInterface $account) {
  $uid = \Drupal::currentUser()
    ->id();
  $user_performed_on = $account
    ->id();
  $roles_added = array_diff($account
    ->getRoles(), $account->original
    ->getRoles());
  if (!empty($roles_added)) {
    role_watchdog_save_entity('Roles added', $uid, RoleWatchdog::ROLE_ADDED, $user_performed_on, $roles_added);
    if (\Drupal::config('role_watchdog.settings')
      ->get('role_watchdog_notify_email') != '') {
      role_watchdog_notify('Roles Added', $roles_added, $user_performed_on);
    }
  }
  $roles_removed = array_diff($account->original
    ->getRoles(), $account
    ->getRoles());
  if (!empty($roles_removed)) {
    role_watchdog_save_entity('Roles removed', $uid, RoleWatchdog::ROLE_REMOVED, $user_performed_on, $roles_removed);
    if (\Drupal::config('role_watchdog.settings')
      ->get('role_watchdog_notify_email') != '') {
      role_watchdog_notify('Roles Removed', $roles_removed, $user_performed_on);
    }
  }
}