You are here

function social_auth_user_delete in Social Auth 3.x

Same name and namespace in other branches
  1. 8.2 social_auth.module \social_auth_user_delete()

Implements hook_ENTITY_TYPE_delete().

File

./social_auth.module, line 34
Allows login using different social networking services.

Code

function social_auth_user_delete(EntityInterface $account) {
  try {
    $storage = \Drupal::entityTypeManager()
      ->getStorage('social_auth');

    /** @var \Drupal\social_auth\Entity\SocialAuth[] $socialAuthUser */
    $users = $storage
      ->loadByProperties([
      'user_id' => $account
        ->id(),
    ]);
    if ($users) {
      $storage
        ->delete($users);
    }
    $storage
      ->resetCache([
      $account
        ->id(),
    ]);
  } catch (\Exception $e) {
    \Drupal::logger('social_auth')
      ->error('Could not delete Social Auth users for user @uid. Error @error', [
      '@uid' => $account
        ->id(),
      '@error' => $e
        ->getMessage(),
    ]);
  }
}