Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
39 / 39 |
|
100.00% |
1 / 1 |
CRAP | n/a |
0 / 0 |
|
crm_install | |
100.00% |
39 / 39 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @file |
5 | * Provides a contact entity type. |
6 | */ |
7 | |
8 | /** |
9 | * Implements hook_install(). |
10 | */ |
11 | function crm_install() { |
12 | $entity_type_manager = \Drupal::entityTypeManager(); |
13 | $site = \Drupal::config('system.site'); |
14 | $name = $site->get('name') ?? 'Default Organization'; |
15 | $mail = $site->get('mail'); |
16 | $storage = $entity_type_manager->getStorage('crm_contact'); |
17 | |
18 | $org = $storage->create([ |
19 | 'name' => $name, |
20 | 'bundle' => 'organization', |
21 | 'emails' => [ |
22 | 'email' => $mail, |
23 | 'primary' => TRUE, |
24 | ], |
25 | ]); |
26 | $org->save(); |
27 | |
28 | $user_storage = $entity_type_manager->getStorage('user'); |
29 | $user = $user_storage->load(1); |
30 | |
31 | $storage->create([ |
32 | 'full_name' => ['given' => $user->get('name')->value], |
33 | 'bundle' => 'person', |
34 | 'emails' => [ |
35 | 'email' => $user->get('mail')->value, |
36 | 'primary' => TRUE, |
37 | ], |
38 | 'primary' => 1, |
39 | ])->save(); |
40 | |
41 | $org->set('primary', 2); |
42 | $org->save(); |
43 | |
44 | $crm_user_storage = $entity_type_manager->getStorage('crm_user'); |
45 | $crm_user_storage->create([ |
46 | 'user' => 1, |
47 | 'crm_contact' => 2, |
48 | ])->save(); |
49 | |
50 | $crm_relationship_storage = $entity_type_manager->getStorage('crm_relationship'); |
51 | $crm_relationship_storage->create([ |
52 | 'bundle' => 'employee', |
53 | 'contact_a' => 2, |
54 | 'contact_b' => 1, |
55 | 'start' => \Drupal::time()->getRequestTime(), |
56 | ])->save(); |
57 | |
58 | } |