Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
49 / 49
100.00% covered (success)
100.00%
1 / 1
CRAP
n/a
0 / 0
crm_install
100.00% covered (success)
100.00%
49 / 49
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * @file
5 * Provides a contact entity type.
6 */
7
8declare(strict_types=1);
9
10use Drupal\Core\Datetime\DrupalDateTime;
11
12/**
13 * Implements hook_install().
14 */
15function crm_install() {
16  $entity_type_manager = \Drupal::entityTypeManager();
17  $site = \Drupal::config('system.site');
18  $name = $site->get('name') ?? 'Default Organization';
19  $mail = $site->get('mail');
20  $storage = $entity_type_manager->getStorage('crm_contact');
21  $detail_storage = $entity_type_manager->getStorage('crm_contact_detail');
22
23  $org_email = $detail_storage->create([
24    'bundle' => 'email',
25    'email' => $mail,
26    'type' => 'main',
27  ]);
28  $org_email->save();
29  $org = $storage->create([
30    'name' => $name,
31    'bundle' => 'organization',
32    'emails' => [
33      'target_id' => $org_email->id(),
34
35    ],
36  ]);
37  $org->save();
38
39  $user_storage = $entity_type_manager->getStorage('user');
40  $user = $user_storage->load(1);
41  $user_email = $detail_storage->create([
42    'bundle' => 'email',
43    'email' => $user->get('mail')->value,
44    'type' => 'main',
45  ]);
46  $user_email->save();
47
48  $storage->create([
49    'full_name' => ['given' => $user->get('name')->value],
50    'bundle' => 'person',
51    'emails' => [
52      'target_id' => $user_email->id(),
53    ],
54    'primary' => 1,
55  ])->save();
56
57  $org->set('primary', 2);
58  $org->save();
59
60  $crm_user_contact_storage = $entity_type_manager->getStorage('crm_user_contact');
61  $crm_user_contact_storage->create([
62    'user' => 1,
63    'crm_contact' => 2,
64  ])->save();
65
66  $crm_relationship_storage = $entity_type_manager->getStorage('crm_relationship');
67  $crm_relationship_storage->create([
68    'bundle' => 'employee',
69    'contacts' => [2, 1],
70    'start' => (new DrupalDateTime('now'))->format('Y-m-d'),
71  ])->save();
72
73}