node.views.inc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. <?php
  2. /**
  3. * @file
  4. * Provide views data and handlers for node.module.
  5. *
  6. * @ingroup views_module_handlers
  7. */
  8. /**
  9. * Implements hook_views_data().
  10. */
  11. function node_views_data() {
  12. // ----------------------------------------------------------------
  13. // 'node' table -- basic table information.
  14. // Define the base group of this table. Fields that don't have a group
  15. // defined will go into this field by default.
  16. $data['node']['table']['group'] = t('Content');
  17. // Advertise this table as a possible base table.
  18. $data['node']['table']['base'] = array(
  19. 'field' => 'nid',
  20. 'title' => t('Content'),
  21. 'weight' => -10,
  22. 'access query tag' => 'node_access',
  23. 'defaults' => array(
  24. 'field' => 'title',
  25. ),
  26. );
  27. $data['node']['table']['entity type'] = 'node';
  28. $data['node']['table']['default_relationship'] = array(
  29. 'node_revision' => array(
  30. 'table' => 'node_revision',
  31. 'field' => 'vid',
  32. ),
  33. );
  34. // ----------------------------------------------------------------
  35. // 'node' table -- fields.
  36. // Node ID / 'nid'.
  37. $data['node']['nid'] = array(
  38. // The item it appears as on the UI,
  39. 'title' => t('Nid'),
  40. // The help that appears on the UI,
  41. 'help' => t('The node ID.'),
  42. // Information for displaying the nid.
  43. 'field' => array(
  44. 'handler' => 'views_handler_field_node',
  45. 'click sortable' => TRUE,
  46. ),
  47. // Information for accepting a nid as an argument.
  48. 'argument' => array(
  49. 'handler' => 'views_handler_argument_node_nid',
  50. 'name field' => 'title',
  51. // The field to display in the summary.
  52. 'numeric' => TRUE,
  53. 'validate type' => 'nid',
  54. ),
  55. // Information for accepting a nid as a filter.
  56. 'filter' => array(
  57. 'handler' => 'views_handler_filter_numeric',
  58. ),
  59. // Information for sorting on a nid.
  60. 'sort' => array(
  61. 'handler' => 'views_handler_sort',
  62. ),
  63. );
  64. // Title.
  65. // This definition has more items in it than it needs to as an example.
  66. $data['node']['title'] = array(
  67. // The item it appears as on the UI,
  68. 'title' => t('Title'),
  69. // The help that appears on the UI,
  70. 'help' => t('The content title.'),
  71. // Information for displaying a title as a field.
  72. 'field' => array(
  73. 'field' => 'title',
  74. // The real field. This could be left out since it is the same.
  75. 'group' => t('Content'),
  76. // The group it appears in on the UI. Could be left out.
  77. 'handler' => 'views_handler_field_node',
  78. 'click sortable' => TRUE,
  79. 'link_to_node default' => TRUE,
  80. ),
  81. 'sort' => array(
  82. 'handler' => 'views_handler_sort',
  83. ),
  84. // Information for accepting a title as a filter.
  85. 'filter' => array(
  86. 'handler' => 'views_handler_filter_string',
  87. ),
  88. 'argument' => array(
  89. 'handler' => 'views_handler_argument_string',
  90. ),
  91. );
  92. // Created field.
  93. $data['node']['created'] = array(
  94. // The item it appears as on the UI,
  95. 'title' => t('Post date'),
  96. // The help that appears on the UI,
  97. 'help' => t('The date the content was posted.'),
  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. // Changed field.
  110. $data['node']['changed'] = array(
  111. // The item it appears as on the UI,
  112. 'title' => t('Updated date'),
  113. // The help that appears on the UI,
  114. 'help' => t('The date the content was last updated.'),
  115. 'field' => array(
  116. 'handler' => 'views_handler_field_date',
  117. 'click sortable' => TRUE,
  118. ),
  119. 'sort' => array(
  120. 'handler' => 'views_handler_sort_date',
  121. ),
  122. 'filter' => array(
  123. 'handler' => 'views_handler_filter_date',
  124. ),
  125. );
  126. // Content type.
  127. $data['node']['type'] = array(
  128. // The item it appears as on the UI,
  129. 'title' => t('Type'),
  130. // The help that appears on the UI,
  131. 'help' => t('The content type (for example, "blog entry", "forum post", "story", etc).'),
  132. 'field' => array(
  133. 'handler' => 'views_handler_field_node_type',
  134. 'click sortable' => TRUE,
  135. ),
  136. 'sort' => array(
  137. 'handler' => 'views_handler_sort',
  138. ),
  139. 'filter' => array(
  140. 'handler' => 'views_handler_filter_node_type',
  141. ),
  142. 'argument' => array(
  143. 'handler' => 'views_handler_argument_node_type',
  144. ),
  145. );
  146. // Published status.
  147. $data['node']['status'] = array(
  148. 'title' => t('Published status'),
  149. 'help' => t('Whether or not the content is published.'),
  150. 'field' => array(
  151. 'handler' => 'views_handler_field_boolean',
  152. 'click sortable' => TRUE,
  153. 'output formats' => array(
  154. 'published-notpublished' => array(t('Published'), t('Not published')),
  155. ),
  156. ),
  157. 'filter' => array(
  158. 'handler' => 'views_handler_filter_boolean_operator',
  159. 'label' => t('Published status'),
  160. 'type' => 'yes-no',
  161. 'use equal' => TRUE,
  162. // Use status = 1 instead of status <> 0 in WHERE statment.
  163. ),
  164. 'sort' => array(
  165. 'handler' => 'views_handler_sort',
  166. ),
  167. );
  168. // Published status + extra.
  169. $data['node']['status_extra'] = array(
  170. 'title' => t('Published status or admin user'),
  171. 'help' => t('Filters out unpublished content if the current user cannot view it.'),
  172. 'filter' => array(
  173. 'field' => 'status',
  174. 'handler' => 'views_handler_filter_node_status',
  175. 'label' => t('Published status or admin user'),
  176. ),
  177. );
  178. // Promote status.
  179. $data['node']['promote'] = array(
  180. 'title' => t('Promoted to front page status'),
  181. 'help' => t('Whether or not the content is promoted to the front page.'),
  182. 'field' => array(
  183. 'handler' => 'views_handler_field_boolean',
  184. 'click sortable' => TRUE,
  185. 'output formats' => array(
  186. 'promoted-notpromoted' => array(t('Promoted'), t('Not promoted')),
  187. ),
  188. ),
  189. 'filter' => array(
  190. 'handler' => 'views_handler_filter_boolean_operator',
  191. 'label' => t('Promoted to front page status'),
  192. 'type' => 'yes-no',
  193. ),
  194. 'sort' => array(
  195. 'handler' => 'views_handler_sort',
  196. ),
  197. );
  198. // Sticky.
  199. $data['node']['sticky'] = array(
  200. // The item it appears as on the UI,
  201. 'title' => t('Sticky status'),
  202. // The help that appears on the UI,
  203. 'help' => t('Whether or not the content is sticky.'),
  204. // Information for displaying a title as a field.
  205. 'field' => array(
  206. 'handler' => 'views_handler_field_boolean',
  207. 'click sortable' => TRUE,
  208. 'output formats' => array(
  209. 'sticky' => array(t('Sticky'), t('Not sticky')),
  210. ),
  211. ),
  212. 'filter' => array(
  213. 'handler' => 'views_handler_filter_boolean_operator',
  214. 'label' => t('Sticky status'),
  215. 'type' => 'yes-no',
  216. ),
  217. 'sort' => array(
  218. 'handler' => 'views_handler_sort',
  219. 'help' => t('Whether or not the content is sticky. To list sticky content first, set this to descending.'),
  220. ),
  221. );
  222. // Define some fields based upon views_handler_field_entity in the entity
  223. // table so they can be re-used with other query backends.
  224. // @see views_handler_field_entity()
  225. $data['views_entity_node']['table']['group'] = t('Content');
  226. $data['node']['view_node']['moved to'] = array('views_entity_node', 'view_node');
  227. $data['views_entity_node']['view_node'] = array(
  228. 'field' => array(
  229. 'title' => t('Link to content'),
  230. 'help' => t('Provide a simple link to the content.'),
  231. 'handler' => 'views_handler_field_node_link',
  232. ),
  233. );
  234. $data['node']['edit_node']['moved to'] = array('views_entity_node', 'edit_node');
  235. $data['views_entity_node']['edit_node'] = array(
  236. 'field' => array(
  237. 'title' => t('Link to edit content'),
  238. 'help' => t('Provide a simple link to edit the content.'),
  239. 'handler' => 'views_handler_field_node_link_edit',
  240. ),
  241. );
  242. $data['node']['delete_node']['moved to'] = array('views_entity_node', 'delete_node');
  243. $data['views_entity_node']['delete_node'] = array(
  244. 'field' => array(
  245. 'title' => t('Link to delete content'),
  246. 'help' => t('Provide a simple link to delete the content.'),
  247. 'handler' => 'views_handler_field_node_link_delete',
  248. ),
  249. );
  250. $data['node']['path'] = array(
  251. 'field' => array(
  252. 'title' => t('Path'),
  253. 'help' => t('The aliased path to this content.'),
  254. 'handler' => 'views_handler_field_node_path',
  255. ),
  256. );
  257. // Bogus fields for aliasing purposes.
  258. $data['node']['created_fulldate'] = array(
  259. 'title' => t('Created date'),
  260. 'help' => t('Date in the form of CCYYMMDD.'),
  261. 'argument' => array(
  262. 'field' => 'created',
  263. 'handler' => 'views_handler_argument_node_created_fulldate',
  264. ),
  265. );
  266. $data['node']['created_year_month'] = array(
  267. 'title' => t('Created year + month'),
  268. 'help' => t('Date in the form of YYYYMM.'),
  269. 'argument' => array(
  270. 'field' => 'created',
  271. 'handler' => 'views_handler_argument_node_created_year_month',
  272. ),
  273. );
  274. $data['node']['created_year'] = array(
  275. 'title' => t('Created year'),
  276. 'help' => t('Date in the form of YYYY.'),
  277. 'argument' => array(
  278. 'field' => 'created',
  279. 'handler' => 'views_handler_argument_node_created_year',
  280. ),
  281. );
  282. $data['node']['created_month'] = array(
  283. 'title' => t('Created month'),
  284. 'help' => t('Date in the form of MM (01 - 12).'),
  285. 'argument' => array(
  286. 'field' => 'created',
  287. 'handler' => 'views_handler_argument_node_created_month',
  288. ),
  289. );
  290. $data['node']['created_day'] = array(
  291. 'title' => t('Created day'),
  292. 'help' => t('Date in the form of DD (01 - 31).'),
  293. 'argument' => array(
  294. 'field' => 'created',
  295. 'handler' => 'views_handler_argument_node_created_day',
  296. ),
  297. );
  298. $data['node']['created_week'] = array(
  299. 'title' => t('Created week'),
  300. 'help' => t('Date in the form of WW (01 - 53).'),
  301. 'argument' => array(
  302. 'field' => 'created',
  303. 'handler' => 'views_handler_argument_node_created_week',
  304. ),
  305. );
  306. $data['node']['changed_fulldate'] = array(
  307. 'title' => t('Updated date'),
  308. 'help' => t('Date in the form of CCYYMMDD.'),
  309. 'argument' => array(
  310. 'field' => 'changed',
  311. 'handler' => 'views_handler_argument_node_created_fulldate',
  312. ),
  313. );
  314. $data['node']['changed_year_month'] = array(
  315. 'title' => t('Updated year + month'),
  316. 'help' => t('Date in the form of YYYYMM.'),
  317. 'argument' => array(
  318. 'field' => 'changed',
  319. 'handler' => 'views_handler_argument_node_created_year_month',
  320. ),
  321. );
  322. $data['node']['changed_year'] = array(
  323. 'title' => t('Updated year'),
  324. 'help' => t('Date in the form of YYYY.'),
  325. 'argument' => array(
  326. 'field' => 'changed',
  327. 'handler' => 'views_handler_argument_node_created_year',
  328. ),
  329. );
  330. $data['node']['changed_month'] = array(
  331. 'title' => t('Updated month'),
  332. 'help' => t('Date in the form of MM (01 - 12).'),
  333. 'argument' => array(
  334. 'field' => 'changed',
  335. 'handler' => 'views_handler_argument_node_created_month',
  336. ),
  337. );
  338. $data['node']['changed_day'] = array(
  339. 'title' => t('Updated day'),
  340. 'help' => t('Date in the form of DD (01 - 31).'),
  341. 'argument' => array(
  342. 'field' => 'changed',
  343. 'handler' => 'views_handler_argument_node_created_day',
  344. ),
  345. );
  346. $data['node']['changed_week'] = array(
  347. 'title' => t('Updated week'),
  348. 'help' => t('Date in the form of WW (01 - 53).'),
  349. 'argument' => array(
  350. 'field' => 'changed',
  351. 'handler' => 'views_handler_argument_node_created_week',
  352. ),
  353. );
  354. // User ID / 'uid' field.
  355. $data['node']['uid'] = array(
  356. 'title' => t('Author uid'),
  357. 'help' => t('The user authoring the content. If you need more fields than the uid add the content: author relationship'),
  358. 'relationship' => array(
  359. 'title' => t('Content author'),
  360. 'help' => t('Relate content to the user who created it.'),
  361. 'handler' => 'views_handler_relationship',
  362. 'base' => 'users',
  363. 'field' => 'uid',
  364. 'label' => t('author'),
  365. ),
  366. 'filter' => array(
  367. 'handler' => 'views_handler_filter_user_name',
  368. ),
  369. 'argument' => array(
  370. 'handler' => 'views_handler_argument_numeric',
  371. ),
  372. 'field' => array(
  373. 'handler' => 'views_handler_field_user',
  374. ),
  375. );
  376. $data['node']['uid_revision'] = array(
  377. 'title' => t('User has a revision'),
  378. 'help' => t('All nodes where a certain user has a revision'),
  379. 'real field' => 'nid',
  380. 'filter' => array(
  381. 'handler' => 'views_handler_filter_node_uid_revision',
  382. ),
  383. 'argument' => array(
  384. 'handler' => 'views_handler_argument_node_uid_revision',
  385. ),
  386. );
  387. $data['node']['version_count'] = array(
  388. 'title' => t('Version Count'),
  389. 'help' => t('The total count of versions/revisions of a certain node.'),
  390. 'field' => array(
  391. 'handler' => 'views_handler_field_node_version_count',
  392. 'field' => 'nid',
  393. 'click sortable' => TRUE,
  394. ),
  395. 'filter' => array(
  396. 'handler' => 'views_handler_filter_node_version_count',
  397. 'allow empty' => FALSE,
  398. ),
  399. 'sort' => array(
  400. 'handler' => 'views_handler_sort_node_version_count',
  401. ),
  402. );
  403. // ----------------------------------------------------------------------
  404. // Content revision table.
  405. // Define the base group of this table. Fields that don't have a group
  406. // defined will go into this field by default.
  407. $data['node_revisions']['moved to'] = 'node_revision';
  408. $data['node_revision']['table']['entity type'] = 'node';
  409. $data['node_revision']['table']['revision'] = TRUE;
  410. $data['node_revision']['table']['group'] = t('Content revision');
  411. // Support the conversion of the field body.
  412. $data['node_revisions']['body']['moved to'] = array('field_revision_data', 'body-revision_id');
  413. // Advertise this table as a possible base table.
  414. $data['node_revision']['table']['base'] = array(
  415. 'field' => 'vid',
  416. 'title' => t('Content revision'),
  417. 'help' => t('Content revision is a history of changes to content.'),
  418. 'defaults' => array(
  419. 'field' => 'title',
  420. ),
  421. );
  422. // For other base tables, explain how we join.
  423. $data['node_revision']['table']['join'] = array(
  424. // Directly links to node table.
  425. 'node' => array(
  426. 'left_field' => 'vid',
  427. 'field' => 'vid',
  428. ),
  429. );
  430. $data['node_revision']['table']['default_relationship'] = array(
  431. 'node' => array(
  432. 'table' => 'node',
  433. 'field' => 'nid',
  434. ),
  435. );
  436. // User ID / 'uid' field for node revision.
  437. $data['node_revision']['uid'] = array(
  438. 'title' => t('User'),
  439. 'help' => t('Relate a content revision to the user who created the revision.'),
  440. 'relationship' => array(
  441. 'handler' => 'views_handler_relationship',
  442. 'base' => 'users',
  443. 'base field' => 'uid',
  444. 'label' => t('revision user'),
  445. ),
  446. );
  447. // Node ID / 'nid'.
  448. $data['node_revision']['nid'] = array(
  449. 'title' => t('Nid'),
  450. // The help that appears on the UI.
  451. 'help' => t('The revision NID of the content revision.'),
  452. // Information for displaying the nid.
  453. 'field' => array(
  454. 'click sortable' => TRUE,
  455. ),
  456. // Information for accepting a nid as an argument.
  457. 'argument' => array(
  458. 'handler' => 'views_handler_argument_node_nid',
  459. 'click sortable' => TRUE,
  460. 'numeric' => TRUE,
  461. ),
  462. // Information for accepting a nid as a filter.
  463. 'filter' => array(
  464. 'handler' => 'views_handler_filter_numeric',
  465. ),
  466. // Information for sorting on a nid.
  467. 'sort' => array(
  468. 'handler' => 'views_handler_sort',
  469. ),
  470. 'relationship' => array(
  471. 'handler' => 'views_handler_relationship',
  472. 'base' => 'node',
  473. 'base field' => 'nid',
  474. 'title' => t('Content'),
  475. 'label' => t('Get the actual content from a content revision.'),
  476. ),
  477. );
  478. // Revision ID / 'vid'.
  479. $data['node_revision']['vid'] = array(
  480. 'title' => t('Vid'),
  481. // The help that appears on the UI.
  482. 'help' => t('The revision ID of the content revision.'),
  483. // Information for displaying the vid.
  484. 'field' => array(
  485. 'click sortable' => TRUE,
  486. ),
  487. // Information for accepting a vid as an argument.
  488. 'argument' => array(
  489. 'handler' => 'views_handler_argument_node_vid',
  490. 'click sortable' => TRUE,
  491. 'numeric' => TRUE,
  492. ),
  493. // Information for accepting a vid as a filter.
  494. 'filter' => array(
  495. 'handler' => 'views_handler_filter_numeric',
  496. ),
  497. // Information for sorting on a vid.
  498. 'sort' => array(
  499. 'handler' => 'views_handler_sort',
  500. ),
  501. 'relationship' => array(
  502. 'handler' => 'views_handler_relationship',
  503. 'base' => 'node',
  504. 'base field' => 'vid',
  505. 'title' => t('Content'),
  506. 'label' => t('Get the actual content from a content revision.'),
  507. ),
  508. );
  509. // Title.
  510. $data['node_revision']['title'] = array(
  511. // The item it appears as on the UI,
  512. 'title' => t('Title'),
  513. // The help that appears on the UI,
  514. 'help' => t('The content title.'),
  515. // Information for displaying a title as a field.
  516. 'field' => array(
  517. 'field' => 'title',
  518. // The real field.
  519. 'handler' => 'views_handler_field_node_revision',
  520. 'click sortable' => TRUE,
  521. ),
  522. 'sort' => array(
  523. 'handler' => 'views_handler_sort',
  524. ),
  525. 'filter' => array(
  526. 'handler' => 'views_handler_filter_string',
  527. ),
  528. 'argument' => array(
  529. 'handler' => 'views_handler_argument_string',
  530. ),
  531. );
  532. // Log field.
  533. $data['node_revision']['log'] = array(
  534. // The item it appears as on the UI,
  535. 'title' => t('Log message'),
  536. // The help that appears on the UI,
  537. 'help' => t('The log message entered when the revision was created.'),
  538. // Information for displaying a title as a field.
  539. 'field' => array(
  540. 'handler' => 'views_handler_field_xss',
  541. ),
  542. 'filter' => array(
  543. 'handler' => 'views_handler_filter_string',
  544. ),
  545. );
  546. // Revision timestamp / 'changed' field.
  547. $data['node_revision']['timestamp'] = array(
  548. // The item it appears as on the UI,
  549. 'title' => t('Updated date'),
  550. // The help that appears on the UI,
  551. 'help' => t('The date the node was last updated.'),
  552. 'field' => array(
  553. 'handler' => 'views_handler_field_date',
  554. 'click sortable' => TRUE,
  555. ),
  556. 'sort' => array(
  557. 'handler' => 'views_handler_sort_date',
  558. ),
  559. 'filter' => array(
  560. 'handler' => 'views_handler_filter_date',
  561. ),
  562. );
  563. $data['node_revision']['link_to_revision'] = array(
  564. 'field' => array(
  565. 'title' => t('Link to revision'),
  566. 'help' => t('Provide a simple link to the revision.'),
  567. 'handler' => 'views_handler_field_node_revision_link',
  568. ),
  569. );
  570. $data['node_revision']['revert_revision'] = array(
  571. 'field' => array(
  572. 'title' => t('Link to revert revision'),
  573. 'help' => t('Provide a simple link to revert to the revision.'),
  574. 'handler' => 'views_handler_field_node_revision_link_revert',
  575. ),
  576. );
  577. $data['node_revision']['delete_revision'] = array(
  578. 'field' => array(
  579. 'title' => t('Link to delete revision'),
  580. 'help' => t('Provide a simple link to delete the content revision.'),
  581. 'handler' => 'views_handler_field_node_revision_link_delete',
  582. ),
  583. );
  584. // ----------------------------------------------------------------------
  585. // Node access table.
  586. // Define the base group of this table. Fields that don't have a group
  587. // defined will go into this field by default.
  588. $data['node_access']['table']['group'] = t('Content access');
  589. // For other base tables, explain how we join.
  590. $data['node_access']['table']['join'] = array(
  591. // Directly links to node table.
  592. 'node' => array(
  593. 'left_field' => 'nid',
  594. 'field' => 'nid',
  595. ),
  596. );
  597. // Node ID / 'nid' field.
  598. $data['node_access']['nid'] = array(
  599. 'title' => t('Access'),
  600. 'help' => t('Filter by access.'),
  601. 'filter' => array(
  602. 'handler' => 'views_handler_filter_node_access',
  603. 'help' => t('Filter for content by view access. <strong>Not necessary if you are using node as your base table.</strong>'),
  604. ),
  605. );
  606. // ----------------------------------------------------------------------
  607. // History table.
  608. // We're actually defining a specific instance of the table, so let's alias
  609. // it so that we can later add the real table for other purposes if we need
  610. // it.
  611. $data['history_user']['moved to'] = 'history';
  612. $data['history']['table']['group'] = t('Content');
  613. // Explain how this table joins to others.
  614. $data['history']['table']['join'] = array(
  615. // Directly links to node table.
  616. 'node' => array(
  617. 'table' => 'history',
  618. 'left_field' => 'nid',
  619. 'field' => 'nid',
  620. 'extra' => array(
  621. array('field' => 'uid', 'value' => '***CURRENT_USER***', 'numeric' => TRUE),
  622. ),
  623. ),
  624. );
  625. $data['history']['timestamp'] = array(
  626. 'title' => t('Has new content'),
  627. 'field' => array(
  628. 'handler' => 'views_handler_field_history_user_timestamp',
  629. 'help' => t('Show a marker if the content is new or updated.'),
  630. ),
  631. 'filter' => array(
  632. 'help' => t('Show only content that is new or updated.'),
  633. 'handler' => 'views_handler_filter_history_user_timestamp',
  634. ),
  635. );
  636. return $data;
  637. }
  638. /**
  639. * Implements hook_views_plugins().
  640. */
  641. function node_views_plugins() {
  642. return array(
  643. 'module' => 'views',
  644. // This just tells our themes are elsewhere.
  645. 'row' => array(
  646. 'node' => array(
  647. 'title' => t('Content'),
  648. 'help' => t('Display the content with standard node view.'),
  649. 'handler' => 'views_plugin_row_node_view',
  650. 'path' => drupal_get_path('module', 'views') . '/modules/node',
  651. // Not necessary for most modules.
  652. 'base' => array('node'),
  653. // Only works with 'node' as base.
  654. 'uses options' => TRUE,
  655. 'type' => 'normal',
  656. 'help topic' => 'style-node',
  657. ),
  658. 'node_rss' => array(
  659. 'title' => t('Content'),
  660. 'help' => t('Display the content with standard node view.'),
  661. 'handler' => 'views_plugin_row_node_rss',
  662. 'path' => drupal_get_path('module', 'views') . '/modules/node',
  663. // Not necessary for most modules.
  664. 'theme' => 'views_view_row_rss',
  665. 'base' => array('node'),
  666. // Only works with 'node' as base.
  667. 'uses options' => TRUE,
  668. 'type' => 'feed',
  669. 'help topic' => 'style-node-rss',
  670. ),
  671. ),
  672. 'argument validator' => array(
  673. 'node' => array(
  674. 'title' => t('Content'),
  675. 'handler' => 'views_plugin_argument_validate_node',
  676. ),
  677. ),
  678. 'argument default' => array(
  679. 'node' => array(
  680. 'title' => t('Content ID from URL'),
  681. 'handler' => 'views_plugin_argument_default_node',
  682. ),
  683. ),
  684. );
  685. }
  686. /**
  687. * Implements hook_preprocess_node().
  688. */
  689. function node_row_node_view_preprocess_node(&$vars) {
  690. $node = $vars['node'];
  691. $options = $vars['view']->style_plugin->row_plugin->options;
  692. // Prevent the comment form from showing up if this is not a page display.
  693. if ($vars['view_mode'] == 'full' && !$vars['view']->display_handler->has_path()) {
  694. $node->comment = FALSE;
  695. }
  696. if (!$options['links']) {
  697. unset($vars['content']['links']);
  698. }
  699. if (module_exists('comment') && !empty($options['comments']) && user_access('access comments') && $node->comment) {
  700. $vars['content']['comments'] = comment_node_page_additions($node);
  701. }
  702. }
  703. /**
  704. * Implements hook_views_query_substitutions().
  705. */
  706. function node_views_query_substitutions() {
  707. return array(
  708. '***ADMINISTER_NODES***' => intval(user_access('administer nodes')),
  709. '***VIEW_OWN_UNPUBLISHED_NODES***' => intval(user_access('view own unpublished content')),
  710. '***BYPASS_NODE_ACCESS***' => intval(user_access('bypass node access')),
  711. );
  712. }
  713. /**
  714. * Implements hook_views_analyze().
  715. */
  716. function node_views_analyze($view) {
  717. $ret = array();
  718. // Check for something other than the default display.
  719. if ($view->base_table == 'node') {
  720. foreach ($view->display as $id => $display) {
  721. if (empty($display->handler)) {
  722. continue;
  723. }
  724. if (!$display->handler->is_defaulted('access') || !$display->handler->is_defaulted('filters')) {
  725. // Check for no access control.
  726. $access = $display->handler->get_option('access');
  727. if (empty($access['type']) || $access['type'] == 'none') {
  728. $select = db_select('role', 'r');
  729. $select->innerJoin('role_permission', 'p', 'r.rid = p.rid');
  730. $result = $select->fields('r', array('name'))
  731. ->fields('p', array('permission'))
  732. ->condition('r.name', array('anonymous user', 'authenticated user'), 'IN')
  733. ->condition('p.permission', 'access content')
  734. ->execute();
  735. foreach ($result as $role) {
  736. $role->safe = TRUE;
  737. $roles[$role->name] = $role;
  738. }
  739. if (!($roles['anonymous user']->safe && $roles['authenticated user']->safe)) {
  740. $ret[] = views_ui_analysis(t('Some roles lack permission to access content, but display %display has no access control.', array('%display' => $display->display_title)), 'warning');
  741. }
  742. $filters = $display->handler->get_option('filters');
  743. foreach ($filters as $filter) {
  744. if ($filter['table'] == 'node' && ($filter['field'] == 'status' || $filter['field'] == 'status_extra')) {
  745. continue 2;
  746. }
  747. }
  748. $ret[] = views_ui_analysis(t('Display %display has no access control but does not contain a filter for published nodes.', array('%display' => $display->display_title)), 'warning');
  749. }
  750. }
  751. }
  752. }
  753. foreach ($view->display as $id => $display) {
  754. if ($display->display_plugin == 'page') {
  755. if ($display->handler->get_option('path') == 'node/%') {
  756. $ret[] = views_ui_analysis(t('Display %display has set node/% as path. This will not produce what you want. If you want to have multiple versions of the node view, use panels.', array('%display' => $display->display_title)), 'warning');
  757. }
  758. }
  759. }
  760. return $ret;
  761. }