-
Notifications
You must be signed in to change notification settings - Fork 0
/
social_auth.module
executable file
·62 lines (51 loc) · 1.3 KB
/
social_auth.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* @file
* Allows login using different social networking services.
*/
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_theme().
*/
function social_auth_theme() {
return [
'login_with' => [
'variables' => ['social_networks' => NULL, 'destination' => NULL],
],
];
}
/**
* Implements hook_preprocess_HOOK().
*/
function social_auth_preprocess_login_with(&$variables) {
$request = \Drupal::request();
$variables['destination'] = $request->get('destination');
$variables['base_path'] = base_path();
$variables['#cache'] = [
'contexts' => ['url.query_args:destination'],
];
}
/**
* Implements hook_ENTITY_TYPE_delete().
*/
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(),
]);
}
}