forked from SU-SWS/stanford_capx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stanford_capx.views.inc
555 lines (507 loc) · 16.7 KB
/
stanford_capx.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
<?php
/**
* @file
* Expose and change data for views.
*/
/**
* Exposed the configuration entity serialized
* @return [type] [description]
*/
function stanford_capx_views_data() {
$data = array();
// First, the entry $data['example_table']['table'] describes properties of
// the actual table – not its content.
// The 'group' index will be used as a prefix in the UI for any of this
// table's fields, sort criteria, etc. so it's easy to tell where they came
// from.
$data['capx_cfe']['table']['group'] = t('Configuration Entity');
// Define this as a base table – a table that can be described in itself by
// views (and not just being brought in as a relationship). In reality this
// is not very useful for this table, as it isn't really a distinct object of
// its own, but it makes a good example.
$data['capx_cfe']['table']['base'] = array(
'field' => 'cfid', // This is the identifier field for the view.
'title' => t('CAPx Configuration Entity'),
'help' => t('CAPx Configuration Entity contains the settings for the mapping and importer entities.'),
'weight' => -10,
);
$data['capx_cfe']['table']['entity type'] = 'capx_cfe';
// Settings table field.
$data['capx_cfe']['settings'] = array(
'title' => t('Configuration Settings'),
'help' => t('Exposes the serialized array of settings.'),
'field' => array(
'handler' => 'views_handler_field_configuration_settings',
'click sortable' => FALSE,
),
);
// Meta table field.
$data['capx_cfe']['meta'] = array(
'title' => t('Meta Data'),
'help' => t('Exposes meta data.'),
'field' => array(
'handler' => 'views_handler_field_configuration_metadata',
'click sortable' => FALSE,
),
);
// Example plain text field.
$data['capx_cfe']['machine_name'] = array(
'title' => t('Machine name'),
'help' => t('The machine name of the entity.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// Example numeric text field.
$data['capx_cfe']['cfid'] = array(
'title' => t('Configuration ID'),
'help' => t('The ID of the configuration entity.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// Example plain text field.
$data['capx_cfe']['title'] = array(
'title' => t('Title'),
'help' => t('The human readable title of the entity.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// Example plain text field.
$data['capx_cfe']['type'] = array(
'title' => t('type'),
'help' => t('The type of entity.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// Mapper edit link.
$data['capx_cfe']['mapper_edit_link'] = array(
'title' => t('Mapping edit link'),
'help' => t('Edit link for mappings'),
'field' => array(
'handler' => 'views_handler_field_mapper_edit_link',
),
);
// Mapper delete link.
$data['capx_cfe']['mapper_delete_link'] = array(
'title' => t('Mapping delete link'),
'help' => t('Delete link for mappings'),
'field' => array(
'handler' => 'views_handler_field_mapper_delete_link',
),
);
// Importer edit link.
$data['capx_cfe']['importer_edit_link'] = array(
'title' => t('Importer edit link'),
'help' => t('Edit link for importers'),
'field' => array(
'handler' => 'views_handler_field_importer_edit_link',
),
);
// Importer sync profiles link.
$data['capx_cfe']['importer_sync_profiles'] = array(
'title' => t('Importer sync profiles action link'),
'help' => t('Sync profiles action'),
'field' => array(
'handler' => 'views_handler_field_importer_sync_profiles',
),
);
// Importer orphan profiles check link.
$data['capx_cfe']['importer_orphan_profiles'] = array(
'title' => t('Importer orphan profiles action link'),
'help' => t('Check orphan profiles action'),
'field' => array(
'handler' => 'views_handler_field_importer_orphan_profiles',
),
);
// Importer delete link.
$data['capx_cfe']['importer_delete_link'] = array(
'title' => t('Importer delete link'),
'help' => t('Delete link for importers'),
'field' => array(
'handler' => 'views_handler_field_importer_delete_link',
),
);
// uid field.
$data['capx_cfe']['uid'] = array(
'title' => t('Author uid'),
'help' => t('The user authoring the content. If you need more fields than the uid add the content: author relationship'),
'relationship' => array(
'title' => t('Author'),
'help' => t('Relate content to the user who created it.'),
'handler' => 'views_handler_relationship',
'base' => 'users',
'field' => 'uid',
'label' => t('author'),
),
'filter' => array(
'handler' => 'views_handler_filter_user_name',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'field' => array(
'handler' => 'views_handler_field_user',
),
);
// Example timestamp field.
$data['capx_cfe']['created'] = array(
'title' => t('Created'),
'help' => t('The date the entity was created.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// Example timestamp field.
$data['capx_cfe']['changed'] = array(
'title' => t('Changed'),
'help' => t('The date the entity was last changed.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// CAPx PROFILES
// ---------------------------------------------------------------------------
// The 'group' index will be used as a prefix in the UI for any of this
// table's fields, sort criteria, etc. so it's easy to tell where they came
// from.
$data['capx_profiles']['table']['group'] = t('CAPx profile');
// Define this as a base table – a table that can be described in itself by
// views (and not just being brought in as a relationship). In reality this
// is not very useful for this table, as it isn't really a distinct object of
// its own, but it makes a good example.
$data['capx_profiles']['table']['base'] = array(
'field' => 'id', // This is the identifier field for the view.
'title' => t('CAPx profile'),
'help' => t('Additional information about a profile.'),
'weight' => -10,
);
// profile table table field.
$data['capx_profiles']['id'] = array(
'title' => t('Profile import id'),
'help' => t('The table id of the imported profile.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort_numeric',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
);
// profile table table field.
$data['capx_profiles']['entity_type'] = array(
'title' => t('Entity Type'),
'help' => t('The entity type of the imported profile.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// profile table table field.
$data['capx_profiles']['bundle_type'] = array(
'title' => t('Bundle Type'),
'help' => t('The bundle type of the imported profile.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// settings table field.
$data['capx_profiles']['importer'] = array(
'title' => t('Importer'),
'help' => t('The machine name of the CAPx importer.'),
'field' => array(
'handler' => 'views_handler_field',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_importer',
),
'argument' => array(
'handler' => 'views_handler_argument_importer',
),
);
$data['capx_profiles']['entity_id'] = array(
'title' => t('Entity ID'),
'help' => t('The entity id.'),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['capx_profiles']['profile_id'] = array(
'title' => t('Profile ID'),
'help' => t('The profile ID that is assigned at the CAP API.'),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'field' => array(
'handler' => 'views_handler_field_capx_profile_id',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['capx_profiles']['orphaned'] = array(
'title' => t('Orphaned Status'),
'help' => t('A boolean value to wether or not the profile has been orphaned.'),
'argument' => array(
'handler' => 'views_handler_argument_boolean',
),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['capx_profiles']['sync'] = array(
'title' => t('Sync Status'),
'help' => t('A boolean value to wether or not the profile is receiving update.'),
'argument' => array(
'handler' => 'views_handler_argument_boolean',
),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['capx_profiles']['last_sync'] = array(
'title' => t('Last Sync'),
'help' => t('The last time the profile was successully updated.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'argument' => array(
'handler' => 'views_handler_argument_date',
),
);
return $data;
}
/**
* Implements hook_views_data_alter()
* @param [type] $data [description]
* @return [type] [description]
*/
function stanford_capx_views_data_alter(&$data) {
// Add a relationship to the capx_profiles table.
$data['node']['capx_profiles'] = array(
'title' => t('CAPx profile info relationship'),
'help' => t('A relationship to the extra profile information from CAP'),
'relationship' => array(
'base' => 'capx_profiles', // Table we're joining to.
'base field' => 'entity_id', // Field on the joined table.
'field' => 'nid', // Real field name on the 'foo' table.
'handler' => 'views_handler_relationship',
'label' => t('CAPx Profile Data'),
'title' => t('CAPx Profile Data'),
'help' => t('A relationship between the imported entity and the additional data stored in the capx_profiles table.'),
),
);
// Add a relationship to the capx_profiles table.
$data['capx_profiles']['node'] = array(
'title' => t('CAPx profile to node relationship'),
'help' => t('A relationship to the node table from CAP profiles'),
'relationship' => array(
'base' => 'node', // Table we're joining to.
'base field' => 'nid', // Field on the joined table.
'field' => 'entity_id', // Real field name on the 'foo' table.
'handler' => 'views_handler_relationship',
'label' => t('CAPx Profile Node Information'),
'title' => t('CAPx Profile Node Information'),
'help' => t('A relationship between the CAPx profiles table and the node table.'),
'extra' => array(
array(
'table' => 'capx_profiles',
'field' => 'entity_type',
'value' => 'node',
),
),
),
);
// Add a relationship to the capx_profiles table.
$data['capx_profiles']['bean'] = array(
'title' => t('CAPx profile to bean relationship'),
'help' => t('A relationship to the bean table from CAP profiles'),
'relationship' => array(
'base' => 'bean', // Table we're joining to.
'base field' => 'bid', // Field on the joined table.
'field' => 'entity_id', // Real field name on the 'foo' table.
'handler' => 'views_handler_relationship',
'label' => t('CAPx Profile BEAN Information'),
'title' => t('CAPx Profile BEAN Information'),
'help' => t('A relationship between the CAPx profiles table and the BEAN table.'),
'extra' => array(
array(
'table' => 'capx_profiles',
'field' => 'entity_type',
'value' => 'bean',
),
),
),
);
// Add a relationship to the capx_profiles table.
$data['capx_profiles']['user'] = array(
'title' => t('CAPx profile to user relationship'),
'help' => t('A relationship to the user table from CAP profiles'),
'relationship' => array(
'base' => 'users', // Table we're joining to.
'base field' => 'uid', // Field on the joined table.
'field' => 'entity_id', // Real field name on the 'foo' table.
'handler' => 'views_handler_relationship',
'label' => t('CAPx Profile User Information'),
'title' => t('CAPx Profile User Information'),
'help' => t('A relationship between the CAPx profiles table and the User table.'),
'extra' => array(
array(
'table' => 'capx_profiles',
'field' => 'entity_type',
'value' => 'user',
),
),
),
);
}
/**
* Implements hook_views_pre_view()
*
*/
function stanford_capx_views_pre_view(&$view, &$display_id, $args) {
// Overview form view all button.
if ($view->name == "importers_overview_page" && $display_id !== "default") {
// Set the footer of the view to have a dynamic more link.
$options = array(
'id' => 'area',
'table' => 'views',
'field' => 'area',
'empty' => FALSE,
'content' => l(t("View all imported profiles"), "admin/config/capx/profiles", array("attributes" => array("class" => array("button")))),
'format' => 'full_html',
'tokenize' => 0,
);
$view->display_handler->set_option('footer', array('text' => $options));
}
// Profile list view page menu in header.
if ($view->name == "capx_admin_profiles" && $display_id == "profiles") {
$menu_block = stanford_capx_management_menu_block();
drupal_add_css($menu_block['#attached']['css'][0]);
$options = array(
'id' => 'area',
'table' => 'views',
'field' => 'area',
'empty' => TRUE,
'content' => $menu_block['#markup'],
'format' => 'full_html',
'tokenize' => 0,
);
$view->display_handler->set_option('header', array('text' => $options));
}
}