-
Notifications
You must be signed in to change notification settings - Fork 17
/
openy_memberships.install
128 lines (114 loc) · 5.18 KB
/
openy_memberships.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
use Drupal\user\Entity\Role;
use Drupal\Core\Field\BaseFieldDefinition;
function openy_memberships_install() {
$role_object = Role::load('anonymous');
$role_object->grantPermission('create family_members profile');
$role_object->grantPermission('delete own family_members profile');
$role_object->grantPermission('view own family_members profile');
$role_object->grantPermission('update own family_members profile');
$role_object->grantPermission('update membership_order commerce_order');
$role_object->grantPermission('view membership commerce_product');
$role_object->grantPermission('view own commerce_order');
$role_object->grantPermission('view membership_addon commerce_addon');
$role_object->grantPermission('view commerce_addon');
$role_object->grantPermission('restful get openy_memberships_summary');
$role_object->save();
$role_object = Role::load('authenticated');
$role_object->grantPermission('create family_members profile');
$role_object->grantPermission('view own family_members profile');
$role_object->grantPermission('update own family_members profile');
$role_object->grantPermission('delete own family_members profile');
$role_object->grantPermission('update membership_order commerce_order');
$role_object->grantPermission('view membership commerce_product');
$role_object->grantPermission('view own commerce_order');
$role_object->grantPermission('view membership_addon commerce_addon');
$role_object->grantPermission('view commerce_addon');
$role_object->grantPermission('restful get openy_memberships_summary');
$role_object->save();
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('commerce_order.commerce_order_item_type.addon');
$config->set('orderType', 'membership_order')->save();
$config = $config_factory->getEditable('jsonapi.settings');
$config->set('read_only', FALSE)->save();
openy_memberships_update_8002();
openy_memberships_update_8003();
openy_memberships_update_8005();
}
/**
* Update order type for addons.
*/
function openy_memberships_update_8001() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('commerce_order.commerce_order_item_type.addon');
$config->set('orderType', 'membership_order')->save();
$role_object = Role::load('anonymous');
$role_object->grantPermission('view membership_addon commerce_addon');
$role_object->grantPermission('view commerce_addon');
$role_object->grantPermission('restful get openy_memberships_summary');
$role_object->save();
$role_object = Role::load('authenticated');
$role_object->grantPermission('view membership_addon commerce_addon');
$role_object->grantPermission('view commerce_addon');
$role_object->grantPermission('restful get openy_memberships_summary');
$role_object->save();
}
/**
* Update fields for profiles.
*/
function openy_memberships_update_8002() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('openy_memberships_front.settings');
$config->set("steps", "BranchSelectorHome\r\nFamily\r\nResults\r\nDiscountFinder\r\nSummary\r\nJoinNow\r\nSuccess")
->save();
$config_importer = \Drupal::service('config_import.importer');
$config_importer->setDirectory(drupal_get_path('module', 'openy_memberships') . '/config/install');
$config_importer->importConfigs(
[
'field.storage.profile.field_email',
'field.storage.profile.field_phone',
'field.field.profile.customer.field_email',
'field.field.profile.customer.field_phone',
'core.entity_form_display.profile.customer.default'
]);
}
/**
* Update permissions.
*/
function openy_memberships_update_8003() {
$role_object = Role::load('anonymous');
$role_object->grantPermission('create customer profile');
$role_object->grantPermission('update own customer profile');
$role_object->grantPermission('view own customer profile');
$role_object->grantPermission('restful get openy_memberships_summary');
$role_object->save();
$role_object = Role::load('authenticated');
$role_object->grantPermission('create customer profile');
$role_object->grantPermission('update own customer profile');
$role_object->grantPermission('view own customer profile');
$role_object->grantPermission('restful get openy_memberships_summary');
$role_object->save();
}
/**
* Update fields for profiles.
*/
function openy_memberships_update_8004() {
$config_importer = \Drupal::service('config_import.importer');
$config_importer->setDirectory(drupal_get_path('module', 'openy_memberships') . '/config/install');
$config_importer->importConfigs(
[
'core.entity_form_display.profile.family_members.default.yml',
'core.entity_view_display.profile.family_members.default.yml',
'field.storage.profile.field_age_group.yml',
'field.field.profile.family_members.field_age_group.yml',
]);
}
/**
* Update config for front app after removing DiscountFinder step.
*/
function openy_memberships_update_8005() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('openy_memberships_front.settings');
$config->set("steps", "BranchSelectorHome\r\nFamily\r\nResults\r\nSummary\r\nJoinNow\r\nSuccess")
->save();
}