-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrupal_helpcrunch.module
More file actions
48 lines (37 loc) · 1.27 KB
/
drupal_helpcrunch.module
File metadata and controls
48 lines (37 loc) · 1.27 KB
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
<?php
/**
* @file
* Primary module hooks for drupal_helpcrunch module.
*/
use Drupal\user\Entity\User;
/**
* Implements hook_page_attachments().
*/
function drupal_helpcrunch_page_attachments(array &$attachments) {
if (!\Drupal::service('router.admin_context')->isAdminRoute()) {
$attachments['#attached']['library'][] = 'drupal_helpcrunch/drupal_helpcrunch_library';
$settings = \Drupal::configFactory()->get('drupal_helpcrunch.settings')->get('settings');
if ($settings) {
$attachments['#attached']['drupalSettings']['drupal_helpcrunch']['helpCrunch']['settings'] = $settings;
}
$user = User::load(\Drupal::currentUser()->id());
if ($user->isAuthenticated()) {
$user_first_name = $user->field_first_name->value;
$user_last_name = $user->field_last_name->value;
if ($user_first_name) {
$username = $user_first_name;
if ($user_last_name) {
$username .= ' ' . $user_last_name;
}
} else {
$username = $user->getDisplayName();
}
$user_data = [
'email' => $user->getEmail(),
'name' => $username,
'user_id' => $user->id(),
];
$attachments['#attached']['drupalSettings']['drupal_helpcrunch']['helpCrunch']['displayName'] = $user_data;
}
}
}