-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration_code.install
92 lines (82 loc) · 2.05 KB
/
registration_code.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
<?php
/**
* @file
* Install, update and uninstall functions for the Registration Code module.
*/
/**
* Implements hook_schema().
*/
function registration_code_schema() {
$schema['registration_code'] = array(
'description' => 'Stores emails and codes to verify user registration.',
'fields' => array(
'rcid' => array(
'description' => 'The ID of the index',
'type' => 'serial',
'not null' => TRUE,
),
'email' => array(
'description' => 'The email',
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
),
'code' => array(
'description' => 'The code',
'type' => 'int',
'not null' => TRUE,
),
),
'indexes' => array(
'execution' => array('email'),
),
'primary key' => array('rcid')
);
return $schema;
}
/**
* Implements hook_install().
*/
function registration_code_install() {
// Create the field.
$field_settings = [
'field_name' => 'registration_code',
'entity_type' => 'user',
'type' => 'integer'
];
\Drupal::entityManager()
->getStorage('field_storage_config')
->create($field_settings)
->save();
// Create the instance.
$instance_settings = [
'field_name' => 'registration_code',
//'required' => 'true',
'label' => 'Registration Code',
'description' => 'Registration Code',
'entity_type' => 'user',
'bundle' => 'user',
'display' => [
'teaser' => [
'label' => 'hidden',
'type' => 'hidden',
],
'default' => [
'label' => 'hidden',
'type' => 'hidden',
]
]
];
\Drupal::entityManager()
->getStorage('field_config')
->create($instance_settings)
->save();
}
/**
* Implements hook_uninstall().
*/
function registration_code_uninstall() {
// Remove the registration_code field.
\Drupal::entityManager()->getStorage('field_config')->load('user.user.registration_code')->delete();
//\Drupal::entityManager()->getStorage('field_storage_config')->load('user.registration_code')->delete();
}