-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeofield.views.inc
95 lines (89 loc) · 3.63 KB
/
geofield.views.inc
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
<?php
/**
* Implements hook_field_views_data().
*/
function geofield_field_views_data(\Drupal\field\FieldStorageConfigInterface $field_storage) {
// Make sure views.views.inc is loaded.
module_load_include('inc', 'views', 'views.views');
// Get the default data from the views module.
$data = views_field_default_views_data($field_storage);
// Loop through all of the results and set our overrides.
foreach ($data as $table_name => $table_data) {
$args = ['@field_name' => $field_storage->getName()];
$target_entity_type = \Drupal::entityTypeManager()->getDefinition($field_storage->getTargetEntityTypeId());
$field_coordinates_table_data = $data[$target_entity_type->getBaseTable() . '__' . $field_storage->getName()][$field_storage->getName()];
// Add proximity handlers.
$data[$table_name][$args['@field_name'] . '_distance'] = [
'group' => 'Content',
'title' => t('Proximity (@field_name)', $args),
'title short' => $field_coordinates_table_data['title short'] . t(":proximity"),
'help' => $field_coordinates_table_data['help'],
'argument' => [
'id' => 'geofield_argument_proximity',
'table' => $table_name,
'entity_type' => $field_storage->get('entity_type'),
'field_name' => $args['@field_name'].'_distance',
'real field' => $args['@field_name'],
'label' => t('Distance to !field_name', $args),
'empty field name' => '- No value -',
'additional fields' => [
$args['@field_name'].'_geo_type',
$args['@field_name'].'_lat',
$args['@field_name'].'_lon',
$args['@field_name'].'_left',
$args['@field_name'].'_top',
$args['@field_name'].'_right',
$args['@field_name'].'_bottom',
$args['@field_name'].'_geohash',
],
],
'filter' => [
'id' => 'geofield_filter_proximity',
'table' => $table_name,
'entity_type' => $field_storage->get('entity_type'),
'field_name' => $args['@field_name'].'_distance',
'real field' => $args['@field_name'],
'label' => t('Distance to !field_name', $args),
'allow empty' => TRUE,
'additional fields' => [
$args['@field_name'].'_geo_type',
$args['@field_name'].'_lat',
$args['@field_name'].'_lon',
$args['@field_name'].'_left',
$args['@field_name'].'_top',
$args['@field_name'].'_right',
$args['@field_name'].'_bottom',
$args['@field_name'].'_geohash',
],
],
'field' => [
'table' => $table_name,
'id' => 'geofield_proximity',
'field_name' => $args['@field_name'].'_distance',
'entity_type' => $field_storage->get('entity_type'),
'real field' => $args['@field_name'],
'additional fields' => [
$args['@field_name'].'_geo_type',
$args['@field_name'].'_lat',
$args['@field_name'].'_lon',
$args['@field_name'].'_left',
$args['@field_name'].'_top',
$args['@field_name'].'_right',
$args['@field_name'].'_bottom',
$args['@field_name'].'_geohash',
],
'element type' => 'div',
'is revision' => (isset($table_data[$args['@field_name']]['field']['is revision']) && $table_data[$args['@field_name']]['field']['is revision']),
'click sortable' => TRUE,
],
'sort' => [
'table' => $table_name,
'id' => 'geofield_proximity',
'field_name' => $args['@field_name'].'_distance',
'entity_type' => $field_storage->get('entity_type'),
'real field' => $args['@field_name'],
],
];
}
return $data;
}