-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact_book.install
93 lines (73 loc) · 2.09 KB
/
contact_book.install
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
# Hook function for creating module database table on install
# hook_schema
function contact_book_schema() {
$schema['contact_book'] = array(
'description' => 'Custom contact book table.',
'fields' => array(
'id'=>array(
'type'=>'serial',
'not null' => TRUE,
'description' => 'Contact book primary key.',
),
'name'=>array(
'type' => 'varchar',
'length' => 15,
'not null' => TRUE,
'description' => 'Contact book user name.',
),
'email'=>array(
'type' => 'varchar',
'length' => 25,
'not null' => TRUE,
'description' => 'Contact book user email.',
),
'phone'=>array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
'description' => 'Contact book user mobile number.',
),
'address'=>array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
'description' => 'Contact book user address.',
),
'country'=>array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'description' => 'Contact book user country.',
),
),
'primary key' => array('id'),
);
return $schema;
}
# Hook function for populating module database table with dummy data on install
# hook_install
function contact_book_install() {
# Add sample contacts
$contacts = array(
'name' => 'Contact',
'email' => '[email protected]',
'phone' => '(+254) 700 000',
'address'=> '123-contact-789',
'country' => 'Kenya',
);
db_insert('contact_book')
->fields($contacts)
->execute();
}
# Hook function for deleting module data on uninstall
# hook_uninstall
function contact_book_uninstall() {
# Clear cached data.
\Drupal::cache('data')
->deleteAll();
# Deleting left-over schema during uninstall.
drupal_uninstall_schema('link_click_count');
# Deleting views during uninstall.
\Drupal::configFactory()->getEditable('views.view.link_click_count')->delete();
}