-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeocomplete.module
More file actions
80 lines (73 loc) · 2.43 KB
/
Copy pathgeocomplete.module
File metadata and controls
80 lines (73 loc) · 2.43 KB
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
<?php
/**
* @file
* Geocomplete module.
*/
/**
* Implements hook_ctools_plugin_directory().
*/
function geocomplete_ctools_plugin_directory($owner, $plugin_type) {
if ($owner == 'search_api_location') {
return 'plugins/' . $plugin_type;
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function geocomplete_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
$flag = FALSE;
foreach ($form_state['view']->filter as $filter_obj) {
if ($filter_obj->options['plugin'] == 'geocomplete') {
// Filter being used in this exposed form is the plugin we define in our module.
$flag = TRUE;
// Add specific class to each geocomplete input.
$form[$filter_obj->field]['#attributes']['class'][] = 'geocomplete-input';
// Add hidden fields for storing lat, lon, etc.
$form[$filter_obj->field . '_geofield'] = array(
'#type' => 'container',
$filter_obj->field . '_lat' => array(
'#type' => 'hidden',
'#attributes' => array(
'data-geocomplete-type' => 'lat',
),
),
$filter_obj->field . '_lng' => array(
'#type' => 'hidden',
'#attributes' => array(
'data-geocomplete-type' => 'lng',
),
),
'#attributes' => array(
'data-geocomplete-src' => $filter_obj->field,
),
);
// Additional types to collect.
$additional_types = array_filter($filter_obj->options['plugin-geocomplete']['additional_types_container']['additional_types']);
if (!empty($additional_types)) {
foreach ($additional_types as $type => $type_flag) {
$form[$filter_obj->field . '_geofield'][$filter_obj->field . '_' . $type] = array(
'#type' => 'hidden',
'#attributes' => array(
'data-geocomplete-type' => $type,
),
);
}
}
}
}
if ($flag && empty($form_state['view']->live_preview)) {
// Geocomplete field is used, add js.
$form['#attached']['js'][] = array(
'data' => 'http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places',
'type' => 'external',
);
$form['#attached']['js'][] = array(
'data' => libraries_get_path('geocomplete') . '/jquery.geocomplete.js',
'type' => 'file',
);
$form['#attached']['js'][] = array(
'data' => drupal_get_path('module', 'geocomplete') . '/geocomplete.js',
'type' => 'file',
);
}
}