node.views.inc 25 KB

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