-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistributors.module
77 lines (63 loc) · 1.85 KB
/
distributors.module
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
<?php
/**
* @file
* Contains distributors.module
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_theme()
*/
function distributors_theme() {
$themes['distributors_search_form'] = [
'render element' => 'form',
'template' => 'distributors_search_form'
];
$themes['distributors_googlemap_results'] = [
'variables' => [
'map_height' => NULL,
'map_width' => NULL,
],
'template' => 'distributors_googlemap_results'
];
return $themes;
}
/**
* Implements hook_views_pre_render().
*/
function distributors_views_pre_render(\Drupal\views\ViewExecutable $view) {
if (isset($view) && ($view->storage->id() == 'distributors')) {
$view->element['#attached']['library'][] = 'distributors/search_page';
}
}
/**
* Implements hook__library_info_alter().
*/
function distributors_library_info_alter(&$libraries, $extension) {
if ($extension == 'distributors') {
foreach($libraries as $key =>$library) {
if($key == 'search_page') {
foreach($libraries['search_page']['js'] as $jkey => $row) {
$pos = stripos($jkey, 'maps.googleapis.com/maps/api');
if ($pos !== false) { //found
//get current language
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
//get api key
$config = \Drupal::config('distributors.settings');
$api_key = $config->get('api_key');
$newkey = '//maps.googleapis.com/maps/api/js?libraries=places&key='.$api_key.'&language='.$language;
if($newkey != $jkey) {
$libraries['search_page']['js'][$newkey] = $libraries['search_page']['js'][$jkey];
unset($libraries['search_page']['js'][$jkey]);
}
break;
}
}
break;
}
}
}
}