-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathopeny_map.install
156 lines (142 loc) · 4.64 KB
/
openy_map.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* @file
* Contains install and update routines.
*/
/**
* Implements hook_install().
*/
function openy_map_install() {
_openy_map_absolutize_config_icon_urls();
_openy_map_set_default_location();
}
/**
* Helper function.
*
* Absolutizes config icon urls.
*/
function _openy_map_absolutize_config_icon_urls() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('openy_map.settings');
$icons_config = $config->get('type_icons');
// @todo Should these be un-absoluted too?
foreach ($icons_config as &$url) {
$absolute_path = \Drupal::service('file_url_generator')->generateAbsoluteString(ltrim($url, '/'));
if ($absolute_path != $url) {
$url = $absolute_path;
}
}
// These should match the relative path in src/Form/SettingsForm.php.
$module_path = \Drupal::service('extension.list.module')->getPath('openy_map');
$search_icon = $module_path . '/img/other/map_icon_red.png';
$search_icon_retina = $module_path . '/img/other/map_icon_red_x2.png';
$branch_icon = $module_path . '/img/map_icon_blue.png';
$camp_icon = $module_path . '/img/map_icon_green.png';
$facility_icon = $module_path . '/img/map_icon_green.png';
// @todo Ensure we're not overwriting if these are already set.
$config->set('type_icons', $icons_config)
->set('leaflet.search_icon', $search_icon)
->set('leaflet.search_icon_retina', $search_icon_retina)
->set('type_icons.branch', $branch_icon)
->set('type_icons.camp', $camp_icon)
->set('type_icons.facility', $facility_icon)
->save(TRUE);
}
/**
* Helper function.
*
* Sets Open Y Maps Leaflet location setting by copying the value of system
* default location if it exists.
*/
function _openy_map_set_default_location() {
$config_factory = \Drupal::configFactory();
$countries = \Drupal::service('country_manager')->getList();
$default_country = $config_factory->get('system.date')->get('country.default');
if (!empty($countries[$default_country])) {
$config_factory->getEditable('openy_map.settings')
->set('leaflet.location', $countries[$default_country])
->save(TRUE);
}
}
/**
* Import map default settings.
*/
function openy_map_update_8001() {
$cim = \Drupal::service('config_import.importer');
$cim->setDirectory(\Drupal::service('extension.list.module')->getPath('openy_map') . '/config/install');
$cim->importConfigs(['openy_map.settings']);
}
/**
* Import map default settings.
*/
function openy_map_update_8002() {
$config_factory = \Drupal::configFactory();
$config_factory->getEditable('openy_map.settings')
->set('map_engine', 'gmaps')
->set('leaflet.base_layer', 'Wikimedia')
->save(TRUE);
_openy_map_absolutize_config_icon_urls();
_openy_map_set_default_location();
}
/**
* Remove obsolete displays in locations view.
*/
function openy_map_update_8003() {
$config_dir = \Drupal::service('extension.list.module')->getPath('openy_map') . '/config/install/';
// Update multiple configurations.
$configs = [
'views.view.locations' => [
'display',
],
];
$config_updater = \Drupal::service('openy_upgrade_tool.param_updater');
foreach ($configs as $config_name => $params) {
$config = $config_dir . $config_name . '.yml';
foreach ($params as $param) {
$config_updater->update($config, $config_name, $param);
}
}
}
/**
* Add Leaflet base layer override configuration.
*/
function openy_map_update_8004() {
$config_updater = \Drupal::service('openy_upgrade_tool.param_updater');
$config_dir = \Drupal::service('extension.list.module')->getPath('openy_map') . '/config/install/';
$config_name = 'openy_map.settings';
$config_path = $config_dir . $config_name . '.yml';
$config_updater->update($config_path, $config_name, 'leaflet.base_layer_override');
}
/**
* Migrate Wikimedia to OpenStreetMap.Mapnik.
*/
function openy_map_update_8006() {
$config_factory = \Drupal::configFactory();
$openy_map_config_leaflet_base_layer = $config_factory->getEditable('openy_map.settings')->get('leaflet.base_layer');
if ($openy_map_config_leaflet_base_layer == 'Wikimedia'){
$config_factory->getEditable('openy_map.settings')
->set('leaflet.base_layer', 'OpenStreetMap.Mapnik')
->save(TRUE);
}
}
/**
* Update path to icons.
*/
function openy_map_update_8007() {
_openy_map_absolutize_config_icon_urls();
}
/**
* Update distance limit units.
*/
function openy_map_update_8008() {
$config_factory = \Drupal::configFactory();
$config_factory->getEditable('openy_map.settings')
->set('distance_limit_units', 'ml')
->save(TRUE);
}
/**
* Update path to icons.
*/
function openy_map_update_8009() {
_openy_map_absolutize_config_icon_urls();
}