node.views.inc 17.3 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Provide views data and handlers for node.module.
 *
 * @ingroup views_module_handlers
 */

10
use Drupal\views\Analyzer;
11
use Drupal\views\ViewExecutable;
12

merlinofchaos's avatar
merlinofchaos committed
13 14 15 16 17
/**
 * Implements hook_views_data().
 */
function node_views_data() {

18 19
  // Define the base group of this table. Fields that don't have a group defined
  // will go into this field by default.
merlinofchaos's avatar
merlinofchaos committed
20 21
  $data['node']['table']['group'] = t('Content');

22
  // Advertise this table as a possible base table.
merlinofchaos's avatar
merlinofchaos committed
23 24 25 26 27 28 29 30 31 32
  $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';
33
  $data['node']['table']['wizard_id'] = 'node';
merlinofchaos's avatar
merlinofchaos committed
34

35 36 37 38 39 40 41 42
  $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',
  );

merlinofchaos's avatar
merlinofchaos committed
43 44
  $data['node']['nid'] = array(
    'title' => t('Nid'),
45
    'help' => t('The node ID.'),
merlinofchaos's avatar
merlinofchaos committed
46
    'field' => array(
aspilicious's avatar
aspilicious committed
47
      'id' => 'node',
merlinofchaos's avatar
merlinofchaos committed
48 49
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
50
      'id' => 'node_nid',
51
      'name field' => 'title',
merlinofchaos's avatar
merlinofchaos committed
52 53 54 55
      'numeric' => TRUE,
      'validate type' => 'nid',
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
56
      'id' => 'numeric',
merlinofchaos's avatar
merlinofchaos committed
57 58
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
59
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
60 61 62 63
    ),
  );

  // This definition has more items in it than it needs to as an example.
64
  $data['node_field_data']['title'] = array(
65 66
    'title' => t('Title'),
    'help' => t('The content title.'),
merlinofchaos's avatar
merlinofchaos committed
67
    'field' => array(
68 69 70 71
      // 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'),
aspilicious's avatar
aspilicious committed
72
      'id' => 'node',
merlinofchaos's avatar
merlinofchaos committed
73 74 75
      'link_to_node default' => TRUE,
     ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
76
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
77 78
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
79
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
80 81
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
82
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
83 84 85
    ),
  );

86
  $data['node_field_data']['created'] = array(
87 88
    'title' => t('Post date'),
    'help' => t('The date the content was posted.'),
merlinofchaos's avatar
merlinofchaos committed
89
    'field' => array(
aspilicious's avatar
aspilicious committed
90
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
91 92
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
93
      'id' => 'date'
merlinofchaos's avatar
merlinofchaos committed
94 95
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
96
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
97 98 99
    ),
  );

100
  $data['node_field_data']['changed'] = array(
101 102
    'title' => t('Updated date'),
    'help' => t('The date the content was last updated.'),
merlinofchaos's avatar
merlinofchaos committed
103
    'field' => array(
aspilicious's avatar
aspilicious committed
104
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
105 106
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
107
      'id' => 'date'
merlinofchaos's avatar
merlinofchaos committed
108 109
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
110
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
111 112 113
    ),
  );

114
  $data['node_field_data']['type'] = array(
115 116
    'title' => t('Type'),
    'help' => t('The content type (for example, "blog entry", "forum post", "story", etc).'),
merlinofchaos's avatar
merlinofchaos committed
117
    'field' => array(
aspilicious's avatar
aspilicious committed
118
      'id' => 'node_type',
merlinofchaos's avatar
merlinofchaos committed
119 120
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
121
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
122 123
    ),
    'filter' => array(
124
      'id' => 'bundle',
merlinofchaos's avatar
merlinofchaos committed
125 126
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
127
      'id' => 'node_type',
merlinofchaos's avatar
merlinofchaos committed
128 129 130
    ),
  );

131
  $data['node_field_data']['status'] = array(
132
    'title' => t('Published status'),
merlinofchaos's avatar
merlinofchaos committed
133 134
    'help' => t('Whether or not the content is published.'),
    'field' => array(
aspilicious's avatar
aspilicious committed
135
      'id' => 'boolean',
merlinofchaos's avatar
merlinofchaos committed
136 137 138 139 140
      'output formats' => array(
        'published-notpublished' => array(t('Published'), t('Not published')),
      ),
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
141
      'id' => 'boolean',
142
      'label' => t('Published status'),
merlinofchaos's avatar
merlinofchaos committed
143
      'type' => 'yes-no',
144 145
      // Use status = 1 instead of status <> 0 in WHERE statement.
      'use_equal' => TRUE,
merlinofchaos's avatar
merlinofchaos committed
146 147
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
148
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
149 150 151
    ),
  );

152
  $data['node_field_data']['status_extra'] = array(
153
    'title' => t('Published status or admin user'),
merlinofchaos's avatar
merlinofchaos committed
154 155 156
    'help' => t('Filters out unpublished content if the current user cannot view it.'),
    'filter' => array(
      'field' => 'status',
aspilicious's avatar
aspilicious committed
157
      'id' => 'node_status',
158
      'label' => t('Published status or admin user'),
merlinofchaos's avatar
merlinofchaos committed
159 160 161
    ),
  );

162
  $data['node_field_data']['promote'] = array(
163
    'title' => t('Promoted to front page status'),
merlinofchaos's avatar
merlinofchaos committed
164 165
    'help' => t('Whether or not the content is promoted to the front page.'),
    'field' => array(
aspilicious's avatar
aspilicious committed
166
      'id' => 'boolean',
merlinofchaos's avatar
merlinofchaos committed
167 168 169 170 171
      'output formats' => array(
        'promoted-notpromoted' => array(t('Promoted'), t('Not promoted')),
      ),
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
172
      'id' => 'boolean',
173
      'label' => t('Promoted to front page status'),
merlinofchaos's avatar
merlinofchaos committed
174 175 176
      'type' => 'yes-no',
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
177
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
178 179 180
    ),
  );

181
  $data['node_field_data']['sticky'] = array(
182
    'title' => t('Sticky status'),
183
    'help' => t('Whether or not the content is sticky.'),
merlinofchaos's avatar
merlinofchaos committed
184
    'field' => array(
aspilicious's avatar
aspilicious committed
185
      'id' => 'boolean',
merlinofchaos's avatar
merlinofchaos committed
186 187 188 189 190
      'output formats' => array(
        'sticky' => array(t('Sticky'), t('Not sticky')),
      ),
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
191
      'id' => 'boolean',
192
      'label' => t('Sticky status'),
merlinofchaos's avatar
merlinofchaos committed
193 194 195
      'type' => 'yes-no',
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
196
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
197 198 199 200
      'help' => t('Whether or not the content is sticky. To list sticky content first, set this to descending.'),
    ),
  );

201
  if (\Drupal::moduleHandler()->moduleExists('content_translation')) {
202 203 204 205
    $data['node']['translation_link'] = array(
      'title' => t('Translation link'),
      'help' => t('Provide a link to the translations overview for nodes.'),
      'field' => array(
206
        'id' => 'content_translation_link',
207 208 209 210
      ),
    );
  }

211 212 213 214 215 216 217 218
  $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',
    ),
  );

219
  $data['node']['view_node'] = array(
merlinofchaos's avatar
merlinofchaos committed
220
    'field' => array(
221
      'title' => t('Link to content'),
merlinofchaos's avatar
merlinofchaos committed
222
      'help' => t('Provide a simple link to the content.'),
aspilicious's avatar
aspilicious committed
223
      'id' => 'node_link',
merlinofchaos's avatar
merlinofchaos committed
224 225 226
    ),
  );

227
  $data['node']['edit_node'] = array(
merlinofchaos's avatar
merlinofchaos committed
228
    'field' => array(
229
      'title' => t('Link to edit content'),
merlinofchaos's avatar
merlinofchaos committed
230
      'help' => t('Provide a simple link to edit the content.'),
aspilicious's avatar
aspilicious committed
231
      'id' => 'node_link_edit',
merlinofchaos's avatar
merlinofchaos committed
232 233 234
    ),
  );

235
  $data['node']['delete_node'] = array(
merlinofchaos's avatar
merlinofchaos committed
236
    'field' => array(
237
      'title' => t('Link to delete content'),
merlinofchaos's avatar
merlinofchaos committed
238
      'help' => t('Provide a simple link to delete the content.'),
aspilicious's avatar
aspilicious committed
239
      'id' => 'node_link_delete',
merlinofchaos's avatar
merlinofchaos committed
240 241 242 243 244 245 246
    ),
  );

  $data['node']['path'] = array(
    'field' => array(
      'title' => t('Path'),
      'help' => t('The aliased path to this content.'),
aspilicious's avatar
aspilicious committed
247
      'id' => 'node_path',
merlinofchaos's avatar
merlinofchaos committed
248 249 250 251 252
    ),
  );

  // Bogus fields for aliasing purposes.

253
  $data['node_field_data']['created_fulldate'] = array(
merlinofchaos's avatar
merlinofchaos committed
254 255 256 257
    'title' => t('Created date'),
    'help' => t('Date in the form of CCYYMMDD.'),
    'argument' => array(
      'field' => 'created',
258
      'id' => 'date_fulldate',
merlinofchaos's avatar
merlinofchaos committed
259 260 261
    ),
  );

262
  $data['node_field_data']['created_year_month'] = array(
merlinofchaos's avatar
merlinofchaos committed
263 264 265 266
    'title' => t('Created year + month'),
    'help' => t('Date in the form of YYYYMM.'),
    'argument' => array(
      'field' => 'created',
267
      'id' => 'date_year_month',
merlinofchaos's avatar
merlinofchaos committed
268 269 270
    ),
  );

271
  $data['node_field_data']['created_year'] = array(
merlinofchaos's avatar
merlinofchaos committed
272 273 274 275
    'title' => t('Created year'),
    'help' => t('Date in the form of YYYY.'),
    'argument' => array(
      'field' => 'created',
276
      'id' => 'date_year',
merlinofchaos's avatar
merlinofchaos committed
277 278 279
    ),
  );

280
  $data['node_field_data']['created_month'] = array(
merlinofchaos's avatar
merlinofchaos committed
281 282 283 284
    'title' => t('Created month'),
    'help' => t('Date in the form of MM (01 - 12).'),
    'argument' => array(
      'field' => 'created',
285
      'id' => 'date_month',
merlinofchaos's avatar
merlinofchaos committed
286 287 288
    ),
  );

289
  $data['node_field_data']['created_day'] = array(
merlinofchaos's avatar
merlinofchaos committed
290 291 292 293
    'title' => t('Created day'),
    'help' => t('Date in the form of DD (01 - 31).'),
    'argument' => array(
      'field' => 'created',
294
      'id' => 'date_day',
merlinofchaos's avatar
merlinofchaos committed
295 296 297
    ),
  );

298
  $data['node_field_data']['created_week'] = array(
merlinofchaos's avatar
merlinofchaos committed
299 300 301 302
    'title' => t('Created week'),
    'help' => t('Date in the form of WW (01 - 53).'),
    'argument' => array(
      'field' => 'created',
303
      'id' => 'date_week',
merlinofchaos's avatar
merlinofchaos committed
304 305 306
    ),
  );

307
  $data['node_field_data']['changed_fulldate'] = array(
merlinofchaos's avatar
merlinofchaos committed
308 309 310 311
    'title' => t('Updated date'),
    'help' => t('Date in the form of CCYYMMDD.'),
    'argument' => array(
      'field' => 'changed',
312
      'id' => 'date_fulldate',
merlinofchaos's avatar
merlinofchaos committed
313 314 315
    ),
  );

316
  $data['node_field_data']['changed_year_month'] = array(
merlinofchaos's avatar
merlinofchaos committed
317 318 319 320
    'title' => t('Updated year + month'),
    'help' => t('Date in the form of YYYYMM.'),
    'argument' => array(
      'field' => 'changed',
321
      'id' => 'date_year_month',
merlinofchaos's avatar
merlinofchaos committed
322 323 324
    ),
  );

325
  $data['node_field_data']['changed_year'] = array(
merlinofchaos's avatar
merlinofchaos committed
326 327 328 329
    'title' => t('Updated year'),
    'help' => t('Date in the form of YYYY.'),
    'argument' => array(
      'field' => 'changed',
330
      'id' => 'date_year',
merlinofchaos's avatar
merlinofchaos committed
331 332 333
    ),
  );

334
  $data['node_field_data']['changed_month'] = array(
merlinofchaos's avatar
merlinofchaos committed
335 336 337 338
    'title' => t('Updated month'),
    'help' => t('Date in the form of MM (01 - 12).'),
    'argument' => array(
      'field' => 'changed',
339
      'id' => 'date_month',
merlinofchaos's avatar
merlinofchaos committed
340 341 342
    ),
  );

343
  $data['node_field_data']['changed_day'] = array(
merlinofchaos's avatar
merlinofchaos committed
344 345 346 347
    'title' => t('Updated day'),
    'help' => t('Date in the form of DD (01 - 31).'),
    'argument' => array(
      'field' => 'changed',
348
      'id' => 'date_day',
merlinofchaos's avatar
merlinofchaos committed
349 350 351
    ),
  );

352
  $data['node_field_data']['changed_week'] = array(
merlinofchaos's avatar
merlinofchaos committed
353 354 355 356
    'title' => t('Updated week'),
    'help' => t('Date in the form of WW (01 - 53).'),
    'argument' => array(
      'field' => 'changed',
357
      'id' => 'date_week',
merlinofchaos's avatar
merlinofchaos committed
358 359 360
    ),
  );

361
  $data['node_field_data']['uid'] = array(
merlinofchaos's avatar
merlinofchaos committed
362 363 364
    '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(
365
      'title' => t('Content author'),
merlinofchaos's avatar
merlinofchaos committed
366
      'help' => t('Relate content to the user who created it.'),
aspilicious's avatar
aspilicious committed
367
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
368 369 370 371 372
      'base' => 'users',
      'field' => 'uid',
      'label' => t('author'),
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
373
      'id' => 'user_name',
merlinofchaos's avatar
merlinofchaos committed
374 375
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
376
      'id' => 'numeric',
merlinofchaos's avatar
merlinofchaos committed
377 378
    ),
    'field' => array(
aspilicious's avatar
aspilicious committed
379
      'id' => 'user',
merlinofchaos's avatar
merlinofchaos committed
380 381 382
    ),
  );

383 384 385 386 387 388 389 390
  $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',
    ),
  );

391
  $data['node_field_data']['uid_revision'] = array(
merlinofchaos's avatar
merlinofchaos committed
392 393 394 395
    'title' => t('User has a revision'),
    'help' => t('All nodes where a certain user has a revision'),
    'real field' => 'nid',
    'filter' => array(
aspilicious's avatar
aspilicious committed
396
      'id' => 'node_uid_revision',
merlinofchaos's avatar
merlinofchaos committed
397 398
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
399
      'id' => 'node_uid_revision',
merlinofchaos's avatar
merlinofchaos committed
400 401 402
    ),
  );

403
  $data['node_revision']['table']['entity type'] = 'node';
404 405
  // Define the base group of this table. Fields that don't have a group defined
  // will go into this field by default.
406 407
  $data['node_revision']['table']['group']  = t('Content revision');
  $data['node_revision']['table']['wizard_id'] = 'node_revision';
merlinofchaos's avatar
merlinofchaos committed
408

409
  // Advertise this table as a possible base table.
410
  $data['node_revision']['table']['base'] = array(
merlinofchaos's avatar
merlinofchaos committed
411 412 413 414 415 416 417 418
    'field' => 'vid',
    'title' => t('Content revision'),
    'help' => t('Content revision is a history of changes to content.'),
    'defaults' => array(
      'field' => 'title',
    ),
  );

419
  // For other base tables, explain how we join.
420
  $data['node_revision']['table']['join'] = array(
merlinofchaos's avatar
merlinofchaos committed
421 422 423 424 425 426
    'node' => array(
      'left_field' => 'vid',
      'field' => 'vid',
    ),
  );

427
  $data['node_revision']['nid'] = array(
428 429 430
    'title' => t('Nid'),
    'help' => t('The revision NID of the content revision.'),
    'field' => array(
431
      'id' => 'standard',
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
    ),
    '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.'),
    ),
  );

452
  $data['node_revision']['vid'] = array(
merlinofchaos's avatar
merlinofchaos committed
453
    'title' => t('Vid'),
454
    'help' => t('The revision ID of the content revision.'),
merlinofchaos's avatar
merlinofchaos committed
455
    'field' => array(
456
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
457 458
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
459
      'id' => 'node_vid',
merlinofchaos's avatar
merlinofchaos committed
460 461 462
      'numeric' => TRUE,
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
463
      'id' => 'numeric',
merlinofchaos's avatar
merlinofchaos committed
464 465
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
466
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
467 468
    ),
    'relationship' => array(
aspilicious's avatar
aspilicious committed
469
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
470 471 472 473 474 475 476
      'base' => 'node',
      'base field' => 'vid',
      'title' => t('Content'),
      'label' => t('Get the actual content from a content revision.'),
    ),
  );

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
  if (\Drupal::moduleHandler()->moduleExists('language')) {
    $data['node_revision']['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',
      ),
    );
  }

  $data['node_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_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']['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_field_revision';

  // For other base tables, explain how we join.
  $data['node_field_revision']['table']['join'] = array(
    'node' => array(
      'left_field' => 'vid',
      'field' => 'vid',
    ),
  );

532
  $data['node_field_revision']['status'] = array(
533 534 535 536 537 538 539 540 541 542 543 544
    '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',
545 546
      // Use status = 1 instead of status <> 0 in WHERE statement.
      'use_equal' => TRUE,
547 548 549 550 551 552
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );

553
  $data['node_field_revision']['title'] = array(
554 555
    'title' => t('Title'),
    'help' => t('The content title.'),
merlinofchaos's avatar
merlinofchaos committed
556
    'field' => array(
557
      'field' => 'title',
aspilicious's avatar
aspilicious committed
558
      'id' => 'node_revision',
merlinofchaos's avatar
merlinofchaos committed
559 560
     ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
561
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
562 563
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
564
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
565 566
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
567
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
568 569 570
    ),
  );

571
  $data['node_field_revision']['changed'] = array(
572 573
    'title' => t('Updated date'),
    'help' => t('The date the node was last updated.'),
merlinofchaos's avatar
merlinofchaos committed
574
    'field' => array(
aspilicious's avatar
aspilicious committed
575
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
576 577
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
578
      'id' => 'date'
merlinofchaos's avatar
merlinofchaos committed
579 580
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
581
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
582 583 584
    ),
  );

585
  $data['node_revision']['link_to_revision'] = array(
merlinofchaos's avatar
merlinofchaos committed
586
    'field' => array(
587
      'title' => t('Link to revision'),
merlinofchaos's avatar
merlinofchaos committed
588
      'help' => t('Provide a simple link to the revision.'),
aspilicious's avatar
aspilicious committed
589
      'id' => 'node_revision_link',
590
      'click sortable' => FALSE,
merlinofchaos's avatar
merlinofchaos committed
591 592 593
    ),
  );

594
  $data['node_revision']['revert_revision'] = array(
merlinofchaos's avatar
merlinofchaos committed
595
    'field' => array(
596
      'title' => t('Link to revert revision'),
merlinofchaos's avatar
merlinofchaos committed
597
      'help' => t('Provide a simple link to revert to the revision.'),
aspilicious's avatar
aspilicious committed
598
      'id' => 'node_revision_link_revert',
599
      'click sortable' => FALSE,
merlinofchaos's avatar
merlinofchaos committed
600 601 602
    ),
  );

603
  $data['node_revision']['delete_revision'] = array(
merlinofchaos's avatar
merlinofchaos committed
604
    'field' => array(
605
      'title' => t('Link to delete revision'),
merlinofchaos's avatar
merlinofchaos committed
606
      'help' => t('Provide a simple link to delete the content revision.'),
aspilicious's avatar
aspilicious committed
607
      'id' => 'node_revision_link_delete',
608
      'click sortable' => FALSE,
merlinofchaos's avatar
merlinofchaos committed
609 610 611
    ),
  );

612 613
  // Define the base group of this table. Fields that don't have a group defined
  // will go into this field by default.
merlinofchaos's avatar
merlinofchaos committed
614 615
  $data['node_access']['table']['group']  = t('Content access');

616
  // For other base tables, explain how we join.
merlinofchaos's avatar
merlinofchaos committed
617 618 619 620 621 622 623 624 625 626
  $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(
aspilicious's avatar
aspilicious committed
627
      'id' => 'node_access',
merlinofchaos's avatar
merlinofchaos committed
628 629 630 631 632 633 634 635 636 637
      '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().
 */
638 639
function node_row_node_view_preprocess_node(&$variables) {
  $options = $variables['view']->rowPlugin->options;
merlinofchaos's avatar
merlinofchaos committed
640 641

  if (!$options['links']) {
642
    unset($variables['content']['links']);
merlinofchaos's avatar
merlinofchaos committed
643 644 645
  }
}

646 647 648 649
/**
 * Implements hook_views_wizard().
 */
function node_views_wizard() {
650
  // @todo: figure this piece out.
651 652 653 654 655
  if (module_exists('statistics')) {
    $plugins['node']['available_sorts']['node_counter-totalcount:DESC'] = t('Number of hits');
  }

}
656 657 658 659 660 661 662 663 664 665

/**
 * 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';
666
  $plugins['entity:node']['provider'] = 'node';
667
}