-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.views.inc
More file actions
114 lines (105 loc) · 2.81 KB
/
data.views.inc
File metadata and controls
114 lines (105 loc) · 2.81 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
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
<?php
/**
* @file
* Views hooks and utility functions.
*/
/**
* Implements hook_views_data().
*
* Dynamically create views integration for any table Data manages.
*/
function data_views_data() {
$data = array();
foreach (data_get_all_tables() as $table) {
/** @var \Drupal\data\Entity\TableConfigInterface $table */
if (!$table->exists()) {
continue;
}
$table_name = $table->id();
$data[$table_name] = [
'table' => [
'group' => t('Data: @table', ['@table' => $table->label()]),
'wizard_id' => 'data',
'base' => [
'field' => $table->table_schema[0]['name'],
'title' => $table->table_schema[0]['label'],
],
],
];
foreach ($table->table_schema as $column) {
$data[$table_name][$column['name']] = [
'field' => [
'id' => 'data_column',
],
'filter' => [
'id' => data_get_views_handler('filter', $column['type']),
],
'argument' => [
'id' => data_get_views_handler('argument', $column['type']),
],
'sort' => [
'id' => data_get_views_handler('sort', $column['type']),
],
'title' => $column['label'],
];
if (!empty($table->meta['relation'][$column['name']])) {
$base_table = $table->meta['relation'][$column['name']]['base_table'];
$base_field = $table->meta['relation'][$column['name']]['base_field'];
$data[$table_name][$column['name']]['relationship'] = [
'title' => $base_table . ' ' . $base_field,
'label' => $base_table . ' ' . $base_field,
'group' => 'Data',
'help' => 'Generated by Data module.',
'id' => 'standard',
'base' => $base_table,
'base field' => $base_field,
'field' => 'new_sector_id',
];
}
}
}
return $data;
}
/**
* Get the handler (class name) for a specified data table field.
*
* @param $type string
* The view handler type ('filter', 'sort', 'argument').
* @param $field_type string
* The field type (int, float, varchar...).
*
* @return
* String: A views handler name.
*/
function data_get_views_handler($type, $field_type) {
switch ($type) {
case 'filter':
switch ($field_type) {
case 'float':
case 'numeric':
case 'int':
case 'serial':
return 'numeric';
case 'datetime':
return 'date';
}
return 'string';
case 'argument':
switch ($field_type) {
case 'int':
case 'float':
case 'serial':
case 'numeric':
return 'numeric';
case 'datetime':
return 'date';
}
return 'string';
case 'sort':
switch ($field_type) {
case 'datetime':
return 'date';
}
return 'standard';
}
}