Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
50 / 50
100.00% covered (success)
100.00%
1 / 1
CRAP
n/a
0 / 0
crm_install
100.00% covered (success)
100.00%
50 / 50
100.00% covered (success)
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 */
11function 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  $detail_storage = $entity_type_manager->getStorage('crm_contact_detail');
18
19  $org_email = $detail_storage->create([
20    'bundle' => 'email',
21    'email' => $mail,
22    'type' => 'main',
23  ]);
24  $org_email->save();
25  $org = $storage->create([
26    'name' => $name,
27    'bundle' => 'organization',
28    'emails' => [
29      'target_id' => $org_email->id(),
30
31    ],
32  ]);
33  $org->save();
34
35  $user_storage = $entity_type_manager->getStorage('user');
36  $user = $user_storage->load(1);
37  $user_email = $detail_storage->create([
38    'bundle' => 'email',
39    'email' => $user->get('mail')->value,
40    'type' => 'main',
41  ]);
42  $user_email->save();
43
44  $storage->create([
45    'full_name' => ['given' => $user->get('name')->value],
46    'bundle' => 'person',
47    'emails' => [
48      'target_id' => $user_email->id(),
49    ],
50    'primary' => 1,
51  ])->save();
52
53  $org->set('primary', 2);
54  $org->save();
55
56  $crm_user_contact_storage = $entity_type_manager->getStorage('crm_user_contact');
57  $crm_user_contact_storage->create([
58    'user' => 1,
59    'crm_contact' => 2,
60  ])->save();
61
62  $crm_relationship_storage = $entity_type_manager->getStorage('crm_relationship');
63  $crm_relationship_storage->create([
64    'bundle' => 'employee',
65    'contact_a' => 2,
66    'contact_b' => 1,
67    'start' => \Drupal::time()->getRequestTime(),
68  ])->save();
69
70}