-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.views.inc
664 lines (602 loc) · 17.2 KB
/
node.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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
<?php
/**
* @file
* Provide views data and handlers for node.module.
*
* @ingroup views_module_handlers
*/
use Drupal\views\Analyzer;
use Drupal\views\ViewExecutable;
/**
* Implements hook_views_data().
*/
function node_views_data() {
// Define the base group of this table. Fields that don't have a group defined
// will go into this field by default.
$data['node']['table']['group'] = t('Content');
// Advertise this table as a possible base table.
$data['node']['table']['base'] = array(
'field' => 'nid',
'title' => t('Content'),
'weight' => -10,
'access query tag' => 'node_access',
'defaults' => array(
'field' => 'title',
),
);
$data['node']['table']['entity type'] = 'node';
$data['node']['table']['wizard_id'] = 'node';
$data['node_field_data']['table']['group'] = t('Content');
$data['node_field_data']['table']['entity type'] = 'node';
$data['node_field_data']['table']['join']['node'] = array(
'type' => 'INNER',
'left_field' => 'nid',
'field' => 'nid',
);
$data['node']['nid'] = array(
'title' => t('Nid'),
'help' => t('The node ID.'),
'field' => array(
'id' => 'node',
),
'argument' => array(
'id' => 'node_nid',
'name field' => 'title',
'numeric' => TRUE,
'validate type' => 'nid',
),
'filter' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
);
// This definition has more items in it than it needs to as an example.
$data['node_field_data']['title'] = array(
'title' => t('Title'),
'help' => t('The content title.'),
'field' => array(
// This is the real field which could be left out since it is the same.
'field' => 'title',
// This is the UI group which could be left out since it is the same.
'group' => t('Content'),
'id' => 'node',
'link_to_node default' => TRUE,
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
);
$data['node_field_data']['created'] = array(
'title' => t('Post date'),
'help' => t('The date the content was posted.'),
'field' => array(
'id' => 'date',
),
'sort' => array(
'id' => 'date'
),
'filter' => array(
'id' => 'date',
),
);
$data['node_field_data']['changed'] = array(
'title' => t('Updated date'),
'help' => t('The date the content was last updated.'),
'field' => array(
'id' => 'date',
),
'sort' => array(
'id' => 'date'
),
'filter' => array(
'id' => 'date',
),
);
$data['node_field_data']['type'] = array(
'title' => t('Type'),
'help' => t('The content type (for example, "blog entry", "forum post", "story", etc).'),
'field' => array(
'id' => 'node_type',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'bundle',
),
'argument' => array(
'id' => 'node_type',
),
);
$data['node_field_data']['status'] = array(
'title' => t('Published status'),
'help' => t('Whether or not the content is published.'),
'field' => array(
'id' => 'boolean',
'output formats' => array(
'published-notpublished' => array(t('Published'), t('Not published')),
),
),
'filter' => array(
'id' => 'boolean',
'label' => t('Published status'),
'type' => 'yes-no',
// Use status = 1 instead of status <> 0 in WHERE statement.
'use_equal' => TRUE,
),
'sort' => array(
'id' => 'standard',
),
);
$data['node_field_data']['status_extra'] = array(
'title' => t('Published status or admin user'),
'help' => t('Filters out unpublished content if the current user cannot view it.'),
'filter' => array(
'field' => 'status',
'id' => 'node_status',
'label' => t('Published status or admin user'),
),
);
$data['node_field_data']['promote'] = array(
'title' => t('Promoted to front page status'),
'help' => t('Whether or not the content is promoted to the front page.'),
'field' => array(
'id' => 'boolean',
'output formats' => array(
'promoted-notpromoted' => array(t('Promoted'), t('Not promoted')),
),
),
'filter' => array(
'id' => 'boolean',
'label' => t('Promoted to front page status'),
'type' => 'yes-no',
),
'sort' => array(
'id' => 'standard',
),
);
$data['node_field_data']['sticky'] = array(
'title' => t('Sticky status'),
'help' => t('Whether or not the content is sticky.'),
'field' => array(
'id' => 'boolean',
'output formats' => array(
'sticky' => array(t('Sticky'), t('Not sticky')),
),
),
'filter' => array(
'id' => 'boolean',
'label' => t('Sticky status'),
'type' => 'yes-no',
),
'sort' => array(
'id' => 'standard',
'help' => t('Whether or not the content is sticky. To list sticky content first, set this to descending.'),
),
);
if (module_exists('language')) {
$data['node']['langcode'] = array(
'title' => t('Language'),
'help' => t('The language the content is in.'),
'field' => array(
'id' => 'node_language',
),
'filter' => array(
'id' => 'language',
),
'argument' => array(
'id' => 'language',
),
'sort' => array(
'id' => 'standard',
),
);
}
if (Drupal::moduleHandler()->moduleExists('content_translation')) {
$data['node']['translation_link'] = array(
'title' => t('Translation link'),
'help' => t('Provide a link to the translations overview for nodes.'),
'field' => array(
'id' => 'content_translation_link',
),
);
}
$data['node']['node_bulk_form'] = array(
'title' => t('Node operations bulk form'),
'help' => t('Add a form element that lets you run operations on multiple nodes.'),
'field' => array(
'id' => 'node_bulk_form',
),
);
$data['node']['view_node'] = array(
'field' => array(
'title' => t('Link to content'),
'help' => t('Provide a simple link to the content.'),
'id' => 'node_link',
),
);
$data['node']['edit_node'] = array(
'field' => array(
'title' => t('Link to edit content'),
'help' => t('Provide a simple link to edit the content.'),
'id' => 'node_link_edit',
),
);
$data['node']['delete_node'] = array(
'field' => array(
'title' => t('Link to delete content'),
'help' => t('Provide a simple link to delete the content.'),
'id' => 'node_link_delete',
),
);
$data['node']['path'] = array(
'field' => array(
'title' => t('Path'),
'help' => t('The aliased path to this content.'),
'id' => 'node_path',
),
);
// Bogus fields for aliasing purposes.
$data['node_field_data']['created_fulldate'] = array(
'title' => t('Created date'),
'help' => t('Date in the form of CCYYMMDD.'),
'argument' => array(
'field' => 'created',
'id' => 'date_fulldate',
),
);
$data['node_field_data']['created_year_month'] = array(
'title' => t('Created year + month'),
'help' => t('Date in the form of YYYYMM.'),
'argument' => array(
'field' => 'created',
'id' => 'date_year_month',
),
);
$data['node_field_data']['created_year'] = array(
'title' => t('Created year'),
'help' => t('Date in the form of YYYY.'),
'argument' => array(
'field' => 'created',
'id' => 'date_year',
),
);
$data['node_field_data']['created_month'] = array(
'title' => t('Created month'),
'help' => t('Date in the form of MM (01 - 12).'),
'argument' => array(
'field' => 'created',
'id' => 'date_month',
),
);
$data['node_field_data']['created_day'] = array(
'title' => t('Created day'),
'help' => t('Date in the form of DD (01 - 31).'),
'argument' => array(
'field' => 'created',
'id' => 'date_day',
),
);
$data['node_field_data']['created_week'] = array(
'title' => t('Created week'),
'help' => t('Date in the form of WW (01 - 53).'),
'argument' => array(
'field' => 'created',
'id' => 'date_week',
),
);
$data['node_field_data']['changed_fulldate'] = array(
'title' => t('Updated date'),
'help' => t('Date in the form of CCYYMMDD.'),
'argument' => array(
'field' => 'changed',
'id' => 'date_fulldate',
),
);
$data['node_field_data']['changed_year_month'] = array(
'title' => t('Updated year + month'),
'help' => t('Date in the form of YYYYMM.'),
'argument' => array(
'field' => 'changed',
'id' => 'date_year_month',
),
);
$data['node_field_data']['changed_year'] = array(
'title' => t('Updated year'),
'help' => t('Date in the form of YYYY.'),
'argument' => array(
'field' => 'changed',
'id' => 'date_year',
),
);
$data['node_field_data']['changed_month'] = array(
'title' => t('Updated month'),
'help' => t('Date in the form of MM (01 - 12).'),
'argument' => array(
'field' => 'changed',
'id' => 'date_month',
),
);
$data['node_field_data']['changed_day'] = array(
'title' => t('Updated day'),
'help' => t('Date in the form of DD (01 - 31).'),
'argument' => array(
'field' => 'changed',
'id' => 'date_day',
),
);
$data['node_field_data']['changed_week'] = array(
'title' => t('Updated week'),
'help' => t('Date in the form of WW (01 - 53).'),
'argument' => array(
'field' => 'changed',
'id' => 'date_week',
),
);
$data['node_field_data']['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('Content author'),
'help' => t('Relate content to the user who created it.'),
'id' => 'standard',
'base' => 'users',
'field' => 'uid',
'label' => t('author'),
),
'filter' => array(
'id' => 'user_name',
),
'argument' => array(
'id' => 'numeric',
),
'field' => array(
'id' => 'user',
),
);
$data['node']['node_listing_empty'] = array(
'title' => t('Empty Node Frontpage behavior'),
'help' => t('Provides a link to the node add overview page.'),
'area' => array(
'id' => 'node_listing_empty',
),
);
$data['node_field_data']['uid_revision'] = array(
'title' => t('User has a revision'),
'help' => t('All nodes where a certain user has a revision'),
'real field' => 'nid',
'filter' => array(
'id' => 'node_uid_revision',
),
'argument' => array(
'id' => 'node_uid_revision',
),
);
$data['node_field_revision']['table']['entity type'] = 'node';
// Define the base group of this table. Fields that don't have a group defined
// will go into this field by default.
$data['node_field_revision']['table']['group'] = t('Content revision');
$data['node_field_revision']['table']['wizard_id'] = 'node_revision';
// Advertise this table as a possible base table.
$data['node_field_revision']['table']['base'] = array(
'field' => 'vid',
'title' => t('Content revision'),
'help' => t('Content revision is a history of changes to content.'),
'defaults' => array(
'field' => 'title',
),
);
// For other base tables, explain how we join.
$data['node_field_revision']['table']['join'] = array(
'node' => array(
'left_field' => 'vid',
'field' => 'vid',
),
);
$data['node_field_revision']['revision_uid'] = array(
'title' => t('User'),
'help' => t('Relate a content revision to the user who created the revision.'),
'relationship' => array(
'id' => 'standard',
'base' => 'users',
'base field' => 'uid',
'label' => t('revision user'),
),
);
$data['node_field_revision']['nid'] = array(
'title' => t('Nid'),
'help' => t('The revision NID of the content revision.'),
'field' => array(
'id' => 'standard',
),
'argument' => array(
'id' => 'node_nid',
'numeric' => TRUE,
),
'filter' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
'relationship' => array(
'id' => 'standard',
'base' => 'node',
'base field' => 'nid',
'title' => t('Content'),
'label' => t('Get the actual content from a content revision.'),
),
);
$data['node_field_revision']['vid'] = array(
'title' => t('Vid'),
'help' => t('The revision ID of the content revision.'),
'field' => array(
'id' => 'standard',
),
'argument' => array(
'id' => 'node_vid',
'numeric' => TRUE,
),
'filter' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
'relationship' => array(
'id' => 'standard',
'base' => 'node',
'base field' => 'vid',
'title' => t('Content'),
'label' => t('Get the actual content from a content revision.'),
),
);
$data['node_field_revision']['status'] = array(
'title' => t('Published'),
'help' => t('Whether or not the content is published.'),
'field' => array(
'id' => 'boolean',
'output formats' => array(
'published-notpublished' => array(t('Published'), t('Not published')),
),
),
'filter' => array(
'id' => 'boolean',
'label' => t('Published'),
'type' => 'yes-no',
// Use status = 1 instead of status <> 0 in WHERE statement.
'use_equal' => TRUE,
),
'sort' => array(
'id' => 'standard',
),
);
$data['node_field_revision']['title'] = array(
'title' => t('Title'),
'help' => t('The content title.'),
'field' => array(
'field' => 'title',
'id' => 'node_revision',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
);
$data['node_field_revision']['log'] = array(
'title' => t('Log message'),
'help' => t('The log message entered when the revision was created.'),
'field' => array(
'id' => 'xss',
),
'filter' => array(
'id' => 'string',
),
);
$data['node_field_revision']['changed'] = array(
'title' => t('Updated date'),
'help' => t('The date the node was last updated.'),
'field' => array(
'id' => 'date',
),
'sort' => array(
'id' => 'date'
),
'filter' => array(
'id' => 'date',
),
);
$data['node_field_revision']['link_to_revision'] = array(
'field' => array(
'title' => t('Link to revision'),
'help' => t('Provide a simple link to the revision.'),
'id' => 'node_revision_link',
'click sortable' => FALSE,
),
);
$data['node_field_revision']['revert_revision'] = array(
'field' => array(
'title' => t('Link to revert revision'),
'help' => t('Provide a simple link to revert to the revision.'),
'id' => 'node_revision_link_revert',
'click sortable' => FALSE,
),
);
$data['node_field_revision']['delete_revision'] = array(
'field' => array(
'title' => t('Link to delete revision'),
'help' => t('Provide a simple link to delete the content revision.'),
'id' => 'node_revision_link_delete',
'click sortable' => FALSE,
),
);
// Define the base group of this table. Fields that don't have a group defined
// will go into this field by default.
$data['node_access']['table']['group'] = t('Content access');
// For other base tables, explain how we join.
$data['node_access']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
$data['node_access']['nid'] = array(
'title' => t('Access'),
'help' => t('Filter by access.'),
'filter' => array(
'id' => 'node_access',
'help' => t('Filter for content by view access. <strong>Not necessary if you are using node as your base table.</strong>'),
),
);
return $data;
}
/**
* Implements hook_preprocess_node().
*/
function node_row_node_view_preprocess_node(&$variables) {
$node = $variables['node'];
$options = $variables['view']->rowPlugin->options;
// Prevent the comment form from showing up if this is not a page display.
if ($variables['view_mode'] == 'full' && !$variables['view']->display_handler->hasPath()) {
$node->comment = FALSE;
}
if (!$options['links']) {
unset($variables['content']['links']);
}
if (!empty($options['comments']) && user_access('access comments') && $node->comment) {
$variables['content']['comments'] = comment_node_page_additions($node);
}
}
/**
* Implements hook_views_wizard().
*/
function node_views_wizard() {
// @todo: figure this piece out.
if (module_exists('statistics')) {
$plugins['node']['available_sorts']['node_counter-totalcount:DESC'] = t('Number of hits');
}
}
/**
* Implements hook_views_plugins_row_alter().
*
* Replaces the generic row plugin by a custom one for nodes.
*
* @see \Drupal\views\Plugin\views\row\EntityRow
*/
function node_views_plugins_row_alter(array &$plugins) {
$plugins['entity:node']['class'] = 'Drupal\node\Plugin\views\row\NodeRow';
$plugins['entity:node']['module'] = 'node';
}