1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Export Drupal Commerce customer profiles to Views.
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* Implements hook_views_data()
|
9
|
*/
|
10
|
function commerce_customer_views_data() {
|
11
|
$data = array();
|
12
|
|
13
|
$data['commerce_customer_profile']['table']['group'] = t('Commerce Customer Profile');
|
14
|
|
15
|
$data['commerce_customer_profile']['table']['base'] = array(
|
16
|
'field' => 'profile_id',
|
17
|
'title' => t('Commerce Customer Profile'),
|
18
|
'help' => t('Customer profiles containing addresses and other customer information.'),
|
19
|
'access query tag' => 'commerce_customer_profile_access',
|
20
|
);
|
21
|
$data['commerce_customer_profile']['table']['entity type'] = 'commerce_customer_profile';
|
22
|
|
23
|
// Expose the profile ID.
|
24
|
$data['commerce_customer_profile']['profile_id'] = array(
|
25
|
'title' => t('Profile ID'),
|
26
|
'help' => t('The unique internal identifier of the profile.'),
|
27
|
'field' => array(
|
28
|
'handler' => 'commerce_customer_handler_field_customer_profile',
|
29
|
'click sortable' => TRUE,
|
30
|
),
|
31
|
'filter' => array(
|
32
|
'handler' => 'views_handler_filter_numeric',
|
33
|
),
|
34
|
'sort' => array(
|
35
|
'handler' => 'views_handler_sort',
|
36
|
),
|
37
|
'argument' => array(
|
38
|
'handler' => 'views_handler_argument_numeric',
|
39
|
),
|
40
|
);
|
41
|
|
42
|
// Expose the profile type.
|
43
|
$data['commerce_customer_profile']['type'] = array(
|
44
|
'title' => t('Type'),
|
45
|
'help' => t('The human-readable name of the type of the customer profile.'),
|
46
|
'field' => array(
|
47
|
'handler' => 'commerce_customer_handler_field_customer_profile_type',
|
48
|
'click sortable' => TRUE,
|
49
|
),
|
50
|
'filter' => array(
|
51
|
'handler' => 'commerce_customer_handler_filter_customer_profile_type',
|
52
|
),
|
53
|
'sort' => array(
|
54
|
'handler' => 'views_handler_sort',
|
55
|
),
|
56
|
'argument' => array(
|
57
|
'handler' => 'views_handler_argument_string',
|
58
|
),
|
59
|
);
|
60
|
|
61
|
// Expose the owner uid.
|
62
|
$data['commerce_customer_profile']['uid'] = array(
|
63
|
'title' => t('Owner'),
|
64
|
'help' => t('Relate a profile to the user it belongs to.'),
|
65
|
'relationship' => array(
|
66
|
'handler' => 'views_handler_relationship',
|
67
|
'base' => 'users',
|
68
|
'field' => 'uid',
|
69
|
'label' => t('Profile owner'),
|
70
|
),
|
71
|
);
|
72
|
|
73
|
// Expose the profile status.
|
74
|
$data['commerce_customer_profile']['status'] = array(
|
75
|
'title' => t('Status'),
|
76
|
'help' => t('Whether or not the profile is active.'),
|
77
|
'field' => array(
|
78
|
'handler' => 'views_handler_field_boolean',
|
79
|
'click sortable' => TRUE,
|
80
|
'output formats' => array(
|
81
|
'active-disabled' => array(t('Active'), t('Disabled')),
|
82
|
),
|
83
|
),
|
84
|
'filter' => array(
|
85
|
'handler' => 'views_handler_filter_boolean_operator',
|
86
|
'label' => t('Active'),
|
87
|
'type' => 'yes-no',
|
88
|
),
|
89
|
'sort' => array(
|
90
|
'handler' => 'views_handler_sort',
|
91
|
),
|
92
|
);
|
93
|
|
94
|
// Expose the created and changed timestamps.
|
95
|
$data['commerce_customer_profile']['created'] = array(
|
96
|
'title' => t('Created date'),
|
97
|
'help' => t('The date the profile was created.'),
|
98
|
'field' => array(
|
99
|
'handler' => 'views_handler_field_date',
|
100
|
'click sortable' => TRUE,
|
101
|
),
|
102
|
'sort' => array(
|
103
|
'handler' => 'views_handler_sort_date',
|
104
|
),
|
105
|
'filter' => array(
|
106
|
'handler' => 'views_handler_filter_date',
|
107
|
),
|
108
|
);
|
109
|
|
110
|
$data['commerce_customer_profile']['created_fulldate'] = array(
|
111
|
'title' => t('Created date'),
|
112
|
'help' => t('In the form of CCYYMMDD.'),
|
113
|
'argument' => array(
|
114
|
'field' => 'created',
|
115
|
'handler' => 'views_handler_argument_node_created_fulldate',
|
116
|
),
|
117
|
);
|
118
|
|
119
|
$data['commerce_customer_profile']['created_year_month'] = array(
|
120
|
'title' => t('Created year + month'),
|
121
|
'help' => t('In the form of YYYYMM.'),
|
122
|
'argument' => array(
|
123
|
'field' => 'created',
|
124
|
'handler' => 'views_handler_argument_node_created_year_month',
|
125
|
),
|
126
|
);
|
127
|
|
128
|
$data['commerce_customer_profile']['created_timestamp_year'] = array(
|
129
|
'title' => t('Created year'),
|
130
|
'help' => t('In the form of YYYY.'),
|
131
|
'argument' => array(
|
132
|
'field' => 'created',
|
133
|
'handler' => 'views_handler_argument_node_created_year',
|
134
|
),
|
135
|
);
|
136
|
|
137
|
$data['commerce_customer_profile']['created_month'] = array(
|
138
|
'title' => t('Created month'),
|
139
|
'help' => t('In the form of MM (01 - 12).'),
|
140
|
'argument' => array(
|
141
|
'field' => 'created',
|
142
|
'handler' => 'views_handler_argument_node_created_month',
|
143
|
),
|
144
|
);
|
145
|
|
146
|
$data['commerce_customer_profile']['created_day'] = array(
|
147
|
'title' => t('Created day'),
|
148
|
'help' => t('In the form of DD (01 - 31).'),
|
149
|
'argument' => array(
|
150
|
'field' => 'created',
|
151
|
'handler' => 'views_handler_argument_node_created_day',
|
152
|
),
|
153
|
);
|
154
|
|
155
|
$data['commerce_customer_profile']['created_week'] = array(
|
156
|
'title' => t('Created week'),
|
157
|
'help' => t('In the form of WW (01 - 53).'),
|
158
|
'argument' => array(
|
159
|
'field' => 'created',
|
160
|
'handler' => 'views_handler_argument_node_created_week',
|
161
|
),
|
162
|
);
|
163
|
|
164
|
$data['commerce_customer_profile']['changed'] = array(
|
165
|
'title' => t('Updated date'),
|
166
|
'help' => t('The date the profile was last updated.'),
|
167
|
'field' => array(
|
168
|
'handler' => 'views_handler_field_date',
|
169
|
'click sortable' => TRUE,
|
170
|
),
|
171
|
'sort' => array(
|
172
|
'handler' => 'views_handler_sort_date',
|
173
|
),
|
174
|
'filter' => array(
|
175
|
'handler' => 'views_handler_filter_date',
|
176
|
),
|
177
|
);
|
178
|
|
179
|
$data['commerce_customer_profile']['changed_fulldate'] = array(
|
180
|
'title' => t('Updated date'),
|
181
|
'help' => t('In the form of CCYYMMDD.'),
|
182
|
'argument' => array(
|
183
|
'field' => 'changed',
|
184
|
'handler' => 'views_handler_argument_node_created_fulldate',
|
185
|
),
|
186
|
);
|
187
|
|
188
|
$data['commerce_customer_profile']['changed_year_month'] = array(
|
189
|
'title' => t('Updated year + month'),
|
190
|
'help' => t('In the form of YYYYMM.'),
|
191
|
'argument' => array(
|
192
|
'field' => 'changed',
|
193
|
'handler' => 'views_handler_argument_node_created_year_month',
|
194
|
),
|
195
|
);
|
196
|
|
197
|
$data['commerce_customer_profile']['changed_timestamp_year'] = array(
|
198
|
'title' => t('Updated year'),
|
199
|
'help' => t('In the form of YYYY.'),
|
200
|
'argument' => array(
|
201
|
'field' => 'changed',
|
202
|
'handler' => 'views_handler_argument_node_created_year',
|
203
|
),
|
204
|
);
|
205
|
|
206
|
$data['commerce_customer_profile']['changed_month'] = array(
|
207
|
'title' => t('Updated month'),
|
208
|
'help' => t('In the form of MM (01 - 12).'),
|
209
|
'argument' => array(
|
210
|
'field' => 'changed',
|
211
|
'handler' => 'views_handler_argument_node_created_month',
|
212
|
),
|
213
|
);
|
214
|
|
215
|
$data['commerce_customer_profile']['changed_day'] = array(
|
216
|
'title' => t('Updated day'),
|
217
|
'help' => t('In the form of DD (01 - 31).'),
|
218
|
'argument' => array(
|
219
|
'field' => 'changed',
|
220
|
'handler' => 'views_handler_argument_node_created_day',
|
221
|
),
|
222
|
);
|
223
|
|
224
|
$data['commerce_customer_profile']['changed_week'] = array(
|
225
|
'title' => t('Updated week'),
|
226
|
'help' => t('In the form of WW (01 - 53).'),
|
227
|
'argument' => array(
|
228
|
'field' => 'changed',
|
229
|
'handler' => 'views_handler_argument_node_created_week',
|
230
|
),
|
231
|
);
|
232
|
|
233
|
// Expose links to operate on the profile.
|
234
|
$data['commerce_customer_profile']['view_customer_profile'] = array(
|
235
|
'field' => array(
|
236
|
'title' => t('Link'),
|
237
|
'help' => t('Provide a simple link to the administrator view of the profile.'),
|
238
|
'handler' => 'commerce_customer_handler_field_customer_profile_link',
|
239
|
),
|
240
|
);
|
241
|
$data['commerce_customer_profile']['edit_customer_profile'] = array(
|
242
|
'field' => array(
|
243
|
'title' => t('Edit link'),
|
244
|
'help' => t('Provide a simple link to edit the profile.'),
|
245
|
'handler' => 'commerce_customer_handler_field_customer_profile_link_edit',
|
246
|
),
|
247
|
);
|
248
|
$data['commerce_customer_profile']['delete_customer_profile'] = array(
|
249
|
'field' => array(
|
250
|
'title' => t('Delete link'),
|
251
|
'help' => t('Provide a simple link to delete the profile.'),
|
252
|
'handler' => 'commerce_customer_handler_field_customer_profile_link_delete',
|
253
|
),
|
254
|
);
|
255
|
|
256
|
$data['commerce_customer_profile']['empty_text'] = array(
|
257
|
'title' => t('Empty text'),
|
258
|
'help' => t('Displays an appropriate empty text message for customer profile lists.'),
|
259
|
'area' => array(
|
260
|
'handler' => 'commerce_customer_handler_area_empty_text',
|
261
|
),
|
262
|
);
|
263
|
|
264
|
return $data;
|
265
|
}
|
266
|
|
267
|
/**
|
268
|
* Implements hook_field_views_data().
|
269
|
*/
|
270
|
function commerce_customer_field_views_data($field) {
|
271
|
$data = field_views_field_default_views_data($field);
|
272
|
|
273
|
// Build an array of bundles the customer profile reference field appears on.
|
274
|
$bundles = array();
|
275
|
|
276
|
foreach ($field['bundles'] as $entity => $entity_bundles) {
|
277
|
$bundles[] = $entity . ' (' . implode(', ', $entity_bundles) . ')';
|
278
|
}
|
279
|
|
280
|
$replacements = array('!field_name' => $field['field_name'], '@bundles' => implode(', ', $bundles));
|
281
|
|
282
|
foreach ($data as $table_name => $table_data) {
|
283
|
foreach ($table_data as $field_name => $field_data) {
|
284
|
if (isset($field_data['filter']['field_name']) && $field_name != 'delta') {
|
285
|
$data[$table_name][$field_name]['relationship'] = array(
|
286
|
'title' => t('Referenced customer profile'),
|
287
|
'label' => t('Customer profile referenced by !field_name', $replacements),
|
288
|
'help' => t('Relate this entity to the customer profile referenced by its !field_name value.', $replacements) . '<br />' . t('Appears in: @bundles.', $replacements),
|
289
|
'base' => 'commerce_customer_profile',
|
290
|
'base field' => 'profile_id',
|
291
|
'handler' => 'views_handler_relationship',
|
292
|
);
|
293
|
}
|
294
|
}
|
295
|
}
|
296
|
|
297
|
return $data;
|
298
|
}
|