comment.views.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. <?php
  2. /**
  3. * @file
  4. * Provide views data and handlers for comment.module.
  5. *
  6. * @ingroup views_module_handlers
  7. */
  8. /**
  9. * Implements hook_views_data().
  10. */
  11. function comment_views_data() {
  12. $data['comments']['moved to'] = 'comment';
  13. $data['comment']['comment']['moved to'] = array('field_data_comment_body', 'comment_body');
  14. $data['comment']['comment']['field']['moved to'] = array('field_data_comment_body', 'comment_body');
  15. // Define the base group of this table. Fields that don't have a group
  16. // defined will go into this field by default.
  17. $data['comment']['table']['group'] = t('Comment');
  18. $data['comment']['table']['base'] = array(
  19. 'field' => 'cid',
  20. 'title' => t('Comment'),
  21. 'help' => t("Comments are responses to node content."),
  22. 'access query tag' => 'comment_access',
  23. );
  24. $data['comment']['table']['entity type'] = 'comment';
  25. // Provide a "default relationship" to keep older views from choking.
  26. $data['comment']['table']['default_relationship'] = array(
  27. 'node' => array(
  28. 'table' => 'node',
  29. 'field' => 'cid',
  30. ),
  31. );
  32. // ----------------------------------------------------------------
  33. // Fields.
  34. // Subject.
  35. $data['comment']['subject'] = array(
  36. 'title' => t('Title'),
  37. 'help' => t('The title of the comment.'),
  38. 'field' => array(
  39. 'handler' => 'views_handler_field_comment',
  40. 'click sortable' => TRUE,
  41. ),
  42. 'filter' => array(
  43. 'handler' => 'views_handler_filter_string',
  44. ),
  45. 'sort' => array(
  46. 'handler' => 'views_handler_sort',
  47. ),
  48. 'argument' => array(
  49. 'handler' => 'views_handler_argument_string',
  50. ),
  51. );
  52. // Comment ID / 'cid'.
  53. $data['comment']['cid'] = array(
  54. 'title' => t('ID'),
  55. 'help' => t('The comment ID of the field'),
  56. 'field' => array(
  57. 'handler' => 'views_handler_field_comment',
  58. 'click sortable' => TRUE,
  59. ),
  60. 'filter' => array(
  61. 'handler' => 'views_handler_filter_numeric',
  62. ),
  63. 'sort' => array(
  64. 'handler' => 'views_handler_sort',
  65. ),
  66. 'argument' => array(
  67. 'handler' => 'views_handler_argument_numeric',
  68. ),
  69. );
  70. // Username of the comment author.
  71. $data['comment']['name'] = array(
  72. 'title' => t('Author'),
  73. 'help' => t("The name of the comment's author. Can be rendered as a link to the author's homepage."),
  74. 'field' => array(
  75. 'handler' => 'views_handler_field_comment_username',
  76. 'click sortable' => TRUE,
  77. ),
  78. 'filter' => array(
  79. 'handler' => 'views_handler_filter_string',
  80. ),
  81. 'sort' => array(
  82. 'handler' => 'views_handler_sort',
  83. ),
  84. 'argument' => array(
  85. 'handler' => 'views_handler_argument_string',
  86. ),
  87. );
  88. // Homepage.
  89. $data['comment']['homepage'] = array(
  90. 'title' => t("Author's website"),
  91. 'help' => t("The website address of the comment's author. Can be rendered as a link. Will be empty if the author is a registered user."),
  92. 'field' => array(
  93. 'handler' => 'views_handler_field_url',
  94. 'click sortable' => TRUE,
  95. ),
  96. 'filter' => array(
  97. 'handler' => 'views_handler_filter_string',
  98. ),
  99. 'sort' => array(
  100. 'handler' => 'views_handler_sort',
  101. ),
  102. 'argument' => array(
  103. 'handler' => 'views_handler_argument_string',
  104. ),
  105. );
  106. // hostname.
  107. $data['comment']['hostname'] = array(
  108. 'title' => t('Hostname'),
  109. 'help' => t('Hostname of user that posted the comment.'),
  110. 'field' => array(
  111. 'handler' => 'views_handler_field',
  112. 'click sortable' => TRUE,
  113. ),
  114. 'filter' => array(
  115. 'handler' => 'views_handler_filter_string',
  116. ),
  117. 'sort' => array(
  118. 'handler' => 'views_handler_sort',
  119. ),
  120. 'argument' => array(
  121. 'handler' => 'views_handler_argument_string',
  122. ),
  123. );
  124. // Email address.
  125. $data['comment']['mail'] = array(
  126. 'title' => t('E-mail'),
  127. 'help' => t('E-mail of user that posted the comment. Will be empty if the author is a registered user.'),
  128. 'field' => array(
  129. 'handler' => 'views_handler_field',
  130. 'click sortable' => TRUE,
  131. ),
  132. 'filter' => array(
  133. 'handler' => 'views_handler_filter_string',
  134. ),
  135. 'sort' => array(
  136. 'handler' => 'views_handler_sort',
  137. ),
  138. 'argument' => array(
  139. 'handler' => 'views_handler_argument_string',
  140. ),
  141. );
  142. // Created - when comment was posted.
  143. $data['comment']['created'] = array(
  144. 'title' => t('Post date'),
  145. 'help' => t('Date and time of when the comment was created.'),
  146. 'field' => array(
  147. 'handler' => 'views_handler_field_date',
  148. 'click sortable' => TRUE,
  149. ),
  150. 'sort' => array(
  151. 'handler' => 'views_handler_sort_date',
  152. ),
  153. 'filter' => array(
  154. 'handler' => 'views_handler_filter_date',
  155. ),
  156. );
  157. $data['comment']['created_fulldata'] = array(
  158. 'title' => t('Created date'),
  159. 'help' => t('Date in the form of CCYYMMDD.'),
  160. 'argument' => array(
  161. 'field' => 'created',
  162. 'handler' => 'views_handler_argument_node_created_fulldate',
  163. ),
  164. );
  165. $data['comment']['created_year_month'] = array(
  166. 'title' => t('Created year + month'),
  167. 'help' => t('Date in the form of YYYYMM.'),
  168. 'argument' => array(
  169. 'field' => 'created',
  170. 'handler' => 'views_handler_argument_node_created_year_month',
  171. ),
  172. );
  173. $data['comment']['created_year'] = array(
  174. 'title' => t('Created year'),
  175. 'help' => t('Date in the form of YYYY.'),
  176. 'argument' => array(
  177. 'field' => 'created',
  178. 'handler' => 'views_handler_argument_node_created_year',
  179. ),
  180. );
  181. $data['comment']['created_month'] = array(
  182. 'title' => t('Created month'),
  183. 'help' => t('Date in the form of MM (01 - 12).'),
  184. 'argument' => array(
  185. 'field' => 'created',
  186. 'handler' => 'views_handler_argument_node_created_month',
  187. ),
  188. );
  189. $data['comment']['created_day'] = array(
  190. 'title' => t('Created day'),
  191. 'help' => t('Date in the form of DD (01 - 31).'),
  192. 'argument' => array(
  193. 'field' => 'created',
  194. 'handler' => 'views_handler_argument_node_created_day',
  195. ),
  196. );
  197. $data['comment']['created_week'] = array(
  198. 'title' => t('Created week'),
  199. 'help' => t('Date in the form of WW (01 - 53).'),
  200. 'argument' => array(
  201. 'field' => 'created',
  202. 'handler' => 'views_handler_argument_node_created_week',
  203. ),
  204. );
  205. // Language field.
  206. if (module_exists('locale')) {
  207. $data['comment']['language'] = array(
  208. 'title' => t('Language'),
  209. 'help' => t('The language the comment is in.'),
  210. 'field' => array(
  211. 'handler' => 'views_handler_field_locale_language',
  212. 'click sortable' => TRUE,
  213. ),
  214. 'filter' => array(
  215. 'handler' => 'views_handler_filter_locale_language',
  216. ),
  217. 'argument' => array(
  218. 'handler' => 'views_handler_argument_locale_language',
  219. ),
  220. 'sort' => array(
  221. 'handler' => 'views_handler_sort',
  222. ),
  223. );
  224. }
  225. $data['comments']['timestamp']['moved to'] = array('comment', 'changed');
  226. // Changed (when comment was last updated).
  227. $data['comment']['changed'] = array(
  228. 'title' => t('Updated date'),
  229. 'help' => t('Date and time of when the comment was last updated.'),
  230. 'field' => array(
  231. 'handler' => 'views_handler_field_date',
  232. 'click sortable' => TRUE,
  233. ),
  234. 'sort' => array(
  235. 'handler' => 'views_handler_sort_date',
  236. ),
  237. 'filter' => array(
  238. 'handler' => 'views_handler_filter_date',
  239. ),
  240. );
  241. $data['comments']['timestamp_fulldate']['moved to'] = array('comment', 'changed_fulldata');
  242. $data['comment']['changed_fulldata'] = array(
  243. 'title' => t('Changed date'),
  244. 'help' => t('Date in the form of CCYYMMDD.'),
  245. 'argument' => array(
  246. 'field' => 'changed',
  247. 'handler' => 'views_handler_argument_node_created_fulldate',
  248. ),
  249. );
  250. $data['comments']['timestamp_year_month']['moved to'] = array('comment', 'changed_year_month');
  251. $data['comment']['changed_year_month'] = array(
  252. 'title' => t('Changed year + month'),
  253. 'help' => t('Date in the form of YYYYMM.'),
  254. 'argument' => array(
  255. 'field' => 'changed',
  256. 'handler' => 'views_handler_argument_node_created_year_month',
  257. ),
  258. );
  259. $data['comments']['timestamp_year']['moved to'] = array('comment', 'changed_year');
  260. $data['comment']['changed_year'] = array(
  261. 'title' => t('Changed year'),
  262. 'help' => t('Date in the form of YYYY.'),
  263. 'argument' => array(
  264. 'field' => 'changed',
  265. 'handler' => 'views_handler_argument_node_created_year',
  266. ),
  267. );
  268. $data['comments']['timestamp_month']['moved to'] = array('comment', 'changed_month');
  269. $data['comment']['changed_month'] = array(
  270. 'title' => t('Changed month'),
  271. 'help' => t('Date in the form of MM (01 - 12).'),
  272. 'argument' => array(
  273. 'field' => 'changed',
  274. 'handler' => 'views_handler_argument_node_created_month',
  275. ),
  276. );
  277. $data['comments']['timestamp_day']['moved to'] = array('comment', 'changed_day');
  278. $data['comment']['changed_day'] = array(
  279. 'title' => t('Changed day'),
  280. 'help' => t('Date in the form of DD (01 - 31).'),
  281. 'argument' => array(
  282. 'field' => 'changed',
  283. 'handler' => 'views_handler_argument_node_created_day',
  284. ),
  285. );
  286. $data['comments']['timestamp_week']['moved to'] = array('comment', 'changed_week');
  287. $data['comment']['changed_week'] = array(
  288. 'title' => t('Changed week'),
  289. 'help' => t('Date in the form of WW (01 - 53).'),
  290. 'argument' => array(
  291. 'field' => 'changed',
  292. 'handler' => 'views_handler_argument_node_created_week',
  293. ),
  294. );
  295. // Status (approved or not).
  296. $data['comment']['status'] = array(
  297. 'title' => t('Approved status'),
  298. 'help' => t('Whether the comment is approved (or still in the moderation queue).'),
  299. 'field' => array(
  300. 'handler' => 'views_handler_field_boolean',
  301. 'click sortable' => TRUE,
  302. 'output formats' => array(
  303. 'approved-not-approved' => array(t('Approved'), t('Not Approved')),
  304. ),
  305. ),
  306. 'filter' => array(
  307. 'handler' => 'views_handler_filter_boolean_operator',
  308. 'label' => t('Approved comment status'),
  309. 'type' => 'yes-no',
  310. ),
  311. 'sort' => array(
  312. 'handler' => 'views_handler_sort',
  313. ),
  314. );
  315. // Link to view comment.
  316. $data['comment']['view_comment'] = array(
  317. 'field' => array(
  318. 'title' => t('Link to comment'),
  319. 'help' => t('Provide a simple link to view the comment.'),
  320. 'handler' => 'views_handler_field_comment_link',
  321. ),
  322. );
  323. // Link to edit comment.
  324. $data['comment']['edit_comment'] = array(
  325. 'field' => array(
  326. 'title' => t('Link to edit comment'),
  327. 'help' => t('Provide a simple link to edit the comment.'),
  328. 'handler' => 'views_handler_field_comment_link_edit',
  329. ),
  330. );
  331. // Link to delete comment.
  332. $data['comment']['delete_comment'] = array(
  333. 'field' => array(
  334. 'title' => t('Link to delete comment'),
  335. 'help' => t('Provide a simple link to delete the comment.'),
  336. 'handler' => 'views_handler_field_comment_link_delete',
  337. ),
  338. );
  339. // Link to approve comment.
  340. $data['comment']['approve_comment'] = array(
  341. 'field' => array(
  342. 'title' => t('Link to approve comment'),
  343. 'help' => t('Provide a simple link to approve the comment.'),
  344. 'handler' => 'views_handler_field_comment_link_approve',
  345. ),
  346. );
  347. // Link to reply to comment.
  348. $data['comment']['replyto_comment'] = array(
  349. 'field' => array(
  350. 'title' => t('Link to reply-to comment'),
  351. 'help' => t('Provide a simple link to reply to the comment.'),
  352. 'handler' => 'views_handler_field_comment_link_reply',
  353. ),
  354. );
  355. $data['comment']['thread'] = array(
  356. 'field' => array(
  357. 'title' => t('Depth'),
  358. 'help' => t('Display the depth of the comment if it is threaded.'),
  359. 'handler' => 'views_handler_field_comment_depth',
  360. ),
  361. 'sort' => array(
  362. 'title' => t('Thread'),
  363. 'help' => t('Sort by the threaded order. This will keep child comments together with their parents.'),
  364. 'handler' => 'views_handler_sort_comment_thread',
  365. ),
  366. );
  367. $data['comment']['nid'] = array(
  368. 'title' => t('Nid'),
  369. 'help' => t('The node ID to which the comment is a reply to.'),
  370. 'relationship' => array(
  371. 'title' => t('Content'),
  372. 'help' => t('The content to which the comment is a reply to.'),
  373. 'base' => 'node',
  374. 'base field' => 'nid',
  375. 'handler' => 'views_handler_relationship',
  376. 'label' => t('Content'),
  377. ),
  378. 'filter' => array(
  379. 'handler' => 'views_handler_filter_numeric',
  380. ),
  381. 'argument' => array(
  382. 'handler' => 'views_handler_argument_numeric',
  383. ),
  384. 'field' => array(
  385. 'handler' => 'views_handler_field_numeric',
  386. ),
  387. );
  388. $data['comment']['cid'] = array(
  389. 'title' => t('Comment id'),
  390. 'help' => t('Unique identifier for the comment.'),
  391. 'filter' => array(
  392. 'handler' => 'views_handler_filter_numeric',
  393. ),
  394. 'argument' => array(
  395. 'handler' => 'views_handler_argument_numeric',
  396. ),
  397. 'field' => array(
  398. 'handler' => 'views_handler_field_numeric',
  399. ),
  400. );
  401. $data['comment']['uid'] = array(
  402. 'title' => t('Author uid'),
  403. 'help' => t('If you need more fields than the uid add the comment: author relationship'),
  404. 'relationship' => array(
  405. 'title' => t('Author'),
  406. 'help' => t("The User ID of the comment's author."),
  407. 'base' => 'users',
  408. 'base field' => 'uid',
  409. 'handler' => 'views_handler_relationship',
  410. 'label' => t('author'),
  411. ),
  412. 'filter' => array(
  413. 'handler' => 'views_handler_filter_numeric',
  414. ),
  415. 'argument' => array(
  416. 'handler' => 'views_handler_argument_numeric',
  417. ),
  418. 'field' => array(
  419. 'handler' => 'views_handler_field_user',
  420. ),
  421. );
  422. $data['comment']['pid'] = array(
  423. 'title' => t('Parent CID'),
  424. 'help' => t('The Comment ID of the parent comment.'),
  425. 'field' => array(
  426. 'handler' => 'views_handler_field',
  427. ),
  428. 'relationship' => array(
  429. 'title' => t('Parent comment'),
  430. 'help' => t('The parent comment.'),
  431. 'base' => 'comment',
  432. 'base field' => 'cid',
  433. 'handler' => 'views_handler_relationship',
  434. 'label' => t('Parent comment'),
  435. ),
  436. );
  437. // ----------------------------------------------------------------------
  438. // 'node_comment_statistics' table.
  439. // Define the group.
  440. $data['node_comment_statistics']['table']['group'] = t('Content');
  441. // Joins.
  442. $data['node_comment_statistics']['table']['join'] = array(
  443. // ...to the node table.
  444. 'node' => array(
  445. 'type' => 'INNER',
  446. 'left_field' => 'nid',
  447. 'field' => 'nid',
  448. ),
  449. );
  450. // Timestamp of the last comment.
  451. $data['node_comment_statistics']['last_comment_timestamp'] = array(
  452. 'title' => t('Last comment time'),
  453. 'help' => t('Date and time of when the last comment was posted.'),
  454. 'field' => array(
  455. 'handler' => 'views_handler_field_last_comment_timestamp',
  456. 'click sortable' => TRUE,
  457. ),
  458. 'sort' => array(
  459. 'handler' => 'views_handler_sort_date',
  460. ),
  461. 'filter' => array(
  462. 'handler' => 'views_handler_filter_date',
  463. ),
  464. );
  465. // Last comment author's username.
  466. $data['node_comment_statistics']['last_comment_name'] = array(
  467. 'title' => t("Last comment author"),
  468. 'help' => t('The name of the author of the last posted comment.'),
  469. 'field' => array(
  470. 'handler' => 'views_handler_field_ncs_last_comment_name',
  471. 'click sortable' => TRUE,
  472. 'no group by' => TRUE,
  473. ),
  474. 'sort' => array(
  475. 'handler' => 'views_handler_sort_ncs_last_comment_name',
  476. 'no group by' => TRUE,
  477. ),
  478. );
  479. // Comment count.
  480. $data['node_comment_statistics']['comment_count'] = array(
  481. 'title' => t('Comment count'),
  482. 'help' => t('The number of comments a node has.'),
  483. 'field' => array(
  484. 'handler' => 'views_handler_field_numeric',
  485. 'click sortable' => TRUE,
  486. ),
  487. 'filter' => array(
  488. 'handler' => 'views_handler_filter_numeric',
  489. ),
  490. 'sort' => array(
  491. 'handler' => 'views_handler_sort',
  492. ),
  493. 'argument' => array(
  494. 'handler' => 'views_handler_argument',
  495. ),
  496. );
  497. // Timestamp of when the last comment update happened.
  498. $data['node_comment_statistics']['last_updated'] = array(
  499. 'title' => t('Updated/commented date'),
  500. 'help' => t('The most recent of last comment posted or node updated time.'),
  501. 'field' => array(
  502. 'handler' => 'views_handler_field_ncs_last_updated',
  503. 'click sortable' => TRUE,
  504. 'no group by' => TRUE,
  505. ),
  506. 'sort' => array(
  507. 'handler' => 'views_handler_sort_ncs_last_updated',
  508. 'no group by' => TRUE,
  509. ),
  510. 'filter' => array(
  511. 'handler' => 'views_handler_filter_ncs_last_updated',
  512. ),
  513. );
  514. $data['node_comment_statistics']['cid'] = array(
  515. 'title' => t('Last comment CID'),
  516. 'help' => t('Display the last comment of a node'),
  517. 'relationship' => array(
  518. 'title' => t('Last comment'),
  519. 'help' => t('The last comment of a node.'),
  520. 'group' => t('Comment'),
  521. 'base' => 'comment',
  522. 'base field' => 'cid',
  523. 'handler' => 'views_handler_relationship',
  524. 'label' => t('Last Comment'),
  525. ),
  526. );
  527. // The user ID / 'uid' of the user who last posted a comment.
  528. $data['node_comment_statistics']['last_comment_uid'] = array(
  529. 'title' => t('Last comment uid'),
  530. 'help' => t('The User ID of the author of the last comment of a node.'),
  531. 'relationship' => array(
  532. 'title' => t('Last comment author'),
  533. 'base' => 'users',
  534. 'base field' => 'uid',
  535. 'handler' => 'views_handler_relationship',
  536. 'label' => t('Last comment author'),
  537. ),
  538. 'filter' => array(
  539. 'handler' => 'views_handler_filter_numeric',
  540. ),
  541. 'argument' => array(
  542. 'handler' => 'views_handler_argument_numeric',
  543. ),
  544. 'field' => array(
  545. 'handler' => 'views_handler_field_numeric',
  546. ),
  547. );
  548. return $data;
  549. }
  550. /**
  551. * Implements hook_views_data_alter() on behalf of comment.module.
  552. *
  553. * Add items to the node table that are relevant to comments.
  554. */
  555. function comment_views_data_alter(&$data) {
  556. // New comments.
  557. $data['node']['new_comments'] = array(
  558. 'title' => t('New comments'),
  559. 'help' => t('The number of new comments on the node.'),
  560. 'field' => array(
  561. 'handler' => 'views_handler_field_node_new_comments',
  562. 'no group by' => TRUE,
  563. ),
  564. );
  565. $data['node']['comments_link'] = array(
  566. 'field' => array(
  567. 'title' => t('Add comment link'),
  568. 'help' => t('Display the standard add comment link used on regular nodes, which will only display if the viewing user has access to add a comment.'),
  569. 'handler' => 'views_handler_field_comment_node_link',
  570. ),
  571. );
  572. // Comment status of the node.
  573. $data['node']['comment'] = array(
  574. 'title' => t('Comment status'),
  575. 'help' => t('Whether comments are enabled or disabled on the node.'),
  576. 'field' => array(
  577. 'handler' => 'views_handler_field_node_comment',
  578. 'click sortable' => TRUE,
  579. ),
  580. 'sort' => array(
  581. 'handler' => 'views_handler_sort',
  582. ),
  583. 'filter' => array(
  584. 'handler' => 'views_handler_filter_node_comment',
  585. ),
  586. );
  587. $data['node']['uid_touch'] = array(
  588. 'title' => t('User posted or commented'),
  589. 'help' => t('Display nodes only if a user posted the node or commented on the node.'),
  590. 'argument' => array(
  591. 'field' => 'uid',
  592. 'name table' => 'users',
  593. 'name field' => 'name',
  594. 'handler' => 'views_handler_argument_comment_user_uid',
  595. 'no group by' => TRUE,
  596. ),
  597. 'filter' => array(
  598. 'field' => 'uid',
  599. 'name table' => 'users',
  600. 'name field' => 'name',
  601. 'handler' => 'views_handler_filter_comment_user_uid',
  602. ),
  603. );
  604. $data['node']['cid'] = array(
  605. 'title' => t('Comments of the node'),
  606. 'help' => t('Relate all comments on the node. This will create 1 duplicate record for every comment. Usually if you need this it is better to create a comment view.'),
  607. 'relationship' => array(
  608. 'group' => t('Comment'),
  609. 'label' => t('Comments'),
  610. 'base' => 'comment',
  611. 'base field' => 'nid',
  612. 'relationship field' => 'nid',
  613. 'handler' => 'views_handler_relationship',
  614. ),
  615. );
  616. }
  617. /**
  618. * Implements hook_views_plugins().
  619. */
  620. function comment_views_plugins() {
  621. return array(
  622. 'module' => 'views',
  623. 'row' => array(
  624. 'comment' => array(
  625. 'title' => t('Comment'),
  626. 'help' => t('Display the comment with standard comment view.'),
  627. 'handler' => 'views_plugin_row_comment_view',
  628. 'theme' => 'views_view_row_comment',
  629. 'path' => drupal_get_path('module', 'views') . '/modules/comment',
  630. // Not necessary for most modules.
  631. 'base' => array('comment'),
  632. // Only works with 'comment' as base.
  633. 'uses options' => TRUE,
  634. 'type' => 'normal',
  635. 'help topic' => 'style-comment',
  636. ),
  637. 'comment_rss' => array(
  638. 'title' => t('Comment'),
  639. 'help' => t('Display the comment as RSS.'),
  640. 'handler' => 'views_plugin_row_comment_rss',
  641. 'theme' => 'views_view_row_rss',
  642. 'path' => drupal_get_path('module', 'views') . '/modules/comment',
  643. // Not necessary for most modules.
  644. 'base' => array('comment'),
  645. // Only works with 'comment' as base.
  646. 'uses options' => TRUE,
  647. 'type' => 'feed',
  648. 'help topic' => 'style-comment-rss',
  649. ),
  650. ),
  651. );
  652. }
  653. /**
  654. * Template helper for theme_views_view_row_comment.
  655. */
  656. function template_preprocess_views_view_row_comment(&$vars) {
  657. $options = $vars['options'];
  658. $view = &$vars['view'];
  659. $plugin = &$view->style_plugin->row_plugin;
  660. $comment = $plugin->comments[$vars['row']->{$vars['field_alias']}];
  661. $node = $plugin->nodes[$comment->nid];
  662. // Put the view on the node so we can retrieve it in the preprocess.
  663. $node->view = &$view;
  664. $build = comment_view_multiple(array($comment->cid => $comment), $node, $plugin->options['view_mode']);
  665. // If displaying the comments without links, remove them from the renderable
  666. // array; there is no way to avoid building them in the first place.
  667. // @see comment_build_content()
  668. if (empty($options['links'])) {
  669. foreach ($build as $cid => &$comment_build) {
  670. if (isset($comment_build['links'])) {
  671. unset($comment_build['links']);
  672. }
  673. }
  674. }
  675. $vars['comment'] = drupal_render($build);
  676. }