comment.views.inc

Provide views data and handlers for comment.module.

File

drupal/core/modules/comment/comment.views.inc
View source
  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. // Define the base group of this table. Fields that don't have a group defined
  13. // will go into this field by default.
  14. $data['comment']['table']['group'] = t('Comment');
  15. $data['comment']['table']['base'] = array(
  16. 'field' => 'cid',
  17. 'title' => t('Comment'),
  18. 'help' => t("Comments are responses to node content."),
  19. 'access query tag' => 'comment_access',
  20. );
  21. $data['comment']['table']['entity type'] = 'comment';
  22. $data['comment']['table']['wizard_id'] = 'comment';
  23. $data['comment']['subject'] = array(
  24. 'title' => t('Title'),
  25. 'help' => t('The title of the comment.'),
  26. 'field' => array(
  27. 'id' => 'comment',
  28. ),
  29. 'filter' => array(
  30. 'id' => 'string',
  31. ),
  32. 'sort' => array(
  33. 'id' => 'standard',
  34. ),
  35. 'argument' => array(
  36. 'id' => 'string',
  37. ),
  38. );
  39. $data['comment']['cid'] = array(
  40. 'title' => t('ID'),
  41. 'help' => t('The comment ID of the field'),
  42. 'field' => array(
  43. 'id' => 'comment',
  44. ),
  45. 'filter' => array(
  46. 'id' => 'numeric',
  47. ),
  48. 'sort' => array(
  49. 'id' => 'standard',
  50. ),
  51. 'argument' => array(
  52. 'id' => 'numeric',
  53. ),
  54. );
  55. $data['comment']['name'] = array(
  56. 'title' => t('Author'),
  57. 'help' => t("The name of the comment's author. Can be rendered as a link to the author's homepage."),
  58. 'field' => array(
  59. 'id' => 'comment_username',
  60. ),
  61. 'filter' => array(
  62. 'id' => 'string',
  63. ),
  64. 'sort' => array(
  65. 'id' => 'standard',
  66. ),
  67. 'argument' => array(
  68. 'id' => 'string',
  69. ),
  70. );
  71. $data['comment']['homepage'] = array(
  72. 'title' => t("Author's website"),
  73. '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."),
  74. 'field' => array(
  75. 'id' => 'url',
  76. ),
  77. 'filter' => array(
  78. 'id' => 'string',
  79. ),
  80. 'sort' => array(
  81. 'id' => 'standard',
  82. ),
  83. 'argument' => array(
  84. 'id' => 'string',
  85. ),
  86. );
  87. $data['comment']['hostname'] = array(
  88. 'title' => t('Hostname'),
  89. 'help' => t('Hostname of user that posted the comment.'),
  90. 'field' => array(
  91. 'id' => 'standard',
  92. ),
  93. 'filter' => array(
  94. 'id' => 'string',
  95. ),
  96. 'sort' => array(
  97. 'id' => 'standard',
  98. ),
  99. 'argument' => array(
  100. 'id' => 'string',
  101. ),
  102. );
  103. $data['comment']['mail'] = array(
  104. 'title' => t('E-mail'),
  105. 'help' => t('E-mail of user that posted the comment. Will be empty if the author is a registered user.'),
  106. 'field' => array(
  107. 'id' => 'standard',
  108. ),
  109. 'filter' => array(
  110. 'id' => 'string',
  111. ),
  112. 'sort' => array(
  113. 'id' => 'standard',
  114. ),
  115. 'argument' => array(
  116. 'id' => 'string',
  117. ),
  118. );
  119. $data['comment']['created'] = array(
  120. 'title' => t('Post date'),
  121. 'help' => t('Date and time of when the comment was created.'),
  122. 'field' => array(
  123. 'id' => 'date',
  124. ),
  125. 'sort' => array(
  126. 'id' => 'date',
  127. ),
  128. 'filter' => array(
  129. 'id' => 'date',
  130. ),
  131. );
  132. if (module_exists('language')) {
  133. $data['comment']['langcode'] = array(
  134. 'title' => t('Language'),
  135. 'help' => t('The language the comment is in.'),
  136. 'field' => array(
  137. 'id' => 'language',
  138. ),
  139. 'filter' => array(
  140. 'id' => 'language',
  141. ),
  142. 'argument' => array(
  143. 'id' => 'language',
  144. ),
  145. 'sort' => array(
  146. 'id' => 'standard',
  147. ),
  148. );
  149. }
  150. $data['comment']['changed'] = array(
  151. 'title' => t('Updated date'),
  152. 'help' => t('Date and time of when the comment was last updated.'),
  153. 'field' => array(
  154. 'id' => 'date',
  155. ),
  156. 'sort' => array(
  157. 'id' => 'date',
  158. ),
  159. 'filter' => array(
  160. 'id' => 'date',
  161. ),
  162. );
  163. $data['comment']['changed_fulldata'] = array(
  164. 'title' => t('Created date'),
  165. 'help' => t('Date in the form of CCYYMMDD.'),
  166. 'argument' => array(
  167. 'field' => 'changed',
  168. 'id' => 'date_fulldate',
  169. ),
  170. );
  171. $data['comment']['changed_year_month'] = array(
  172. 'title' => t('Created year + month'),
  173. 'help' => t('Date in the form of YYYYMM.'),
  174. 'argument' => array(
  175. 'field' => 'changed',
  176. 'id' => 'date_year_month',
  177. ),
  178. );
  179. $data['comment']['changed_year'] = array(
  180. 'title' => t('Created year'),
  181. 'help' => t('Date in the form of YYYY.'),
  182. 'argument' => array(
  183. 'field' => 'changed',
  184. 'id' => 'date_year',
  185. ),
  186. );
  187. $data['comment']['changed_month'] = array(
  188. 'title' => t('Created month'),
  189. 'help' => t('Date in the form of MM (01 - 12).'),
  190. 'argument' => array(
  191. 'field' => 'changed',
  192. 'id' => 'date_month',
  193. ),
  194. );
  195. $data['comment']['changed_day'] = array(
  196. 'title' => t('Created day'),
  197. 'help' => t('Date in the form of DD (01 - 31).'),
  198. 'argument' => array(
  199. 'field' => 'changed',
  200. 'id' => 'date_day',
  201. ),
  202. );
  203. $data['comment']['changed_week'] = array(
  204. 'title' => t('Created week'),
  205. 'help' => t('Date in the form of WW (01 - 53).'),
  206. 'argument' => array(
  207. 'field' => 'changed',
  208. 'id' => 'date_week',
  209. ),
  210. );
  211. $data['comment']['status'] = array(
  212. 'title' => t('Approved status'),
  213. 'help' => t('Whether the comment is approved (or still in the moderation queue).'),
  214. 'field' => array(
  215. 'id' => 'boolean',
  216. 'output formats' => array(
  217. 'approved-not-approved' => array(t('Approved'), t('Not Approved')),
  218. ),
  219. ),
  220. 'filter' => array(
  221. 'id' => 'boolean',
  222. 'label' => t('Approved comment status'),
  223. 'type' => 'yes-no',
  224. ),
  225. 'sort' => array(
  226. 'id' => 'standard',
  227. ),
  228. );
  229. $data['comment']['view_comment'] = array(
  230. 'field' => array(
  231. 'title' => t('Link to comment'),
  232. 'help' => t('Provide a simple link to view the comment.'),
  233. 'id' => 'comment_link',
  234. ),
  235. );
  236. $data['comment']['edit_comment'] = array(
  237. 'field' => array(
  238. 'title' => t('Link to edit comment'),
  239. 'help' => t('Provide a simple link to edit the comment.'),
  240. 'id' => 'comment_link_edit',
  241. ),
  242. );
  243. $data['comment']['delete_comment'] = array(
  244. 'field' => array(
  245. 'title' => t('Link to delete comment'),
  246. 'help' => t('Provide a simple link to delete the comment.'),
  247. 'id' => 'comment_link_delete',
  248. ),
  249. );
  250. $data['comment']['approve_comment'] = array(
  251. 'field' => array(
  252. 'title' => t('Link to approve comment'),
  253. 'help' => t('Provide a simple link to approve the comment.'),
  254. 'id' => 'comment_link_approve',
  255. ),
  256. );
  257. $data['comment']['replyto_comment'] = array(
  258. 'field' => array(
  259. 'title' => t('Link to reply-to comment'),
  260. 'help' => t('Provide a simple link to reply to the comment.'),
  261. 'id' => 'comment_link_reply',
  262. ),
  263. );
  264. $data['comment']['thread'] = array(
  265. 'field' => array(
  266. 'title' => t('Depth'),
  267. 'help' => t('Display the depth of the comment if it is threaded.'),
  268. 'id' => 'comment_depth',
  269. ),
  270. 'sort' => array(
  271. 'title' => t('Thread'),
  272. 'help' => t('Sort by the threaded order. This will keep child comments together with their parents.'),
  273. 'id' => 'comment_thread',
  274. ),
  275. );
  276. $data['comment']['nid'] = array(
  277. 'title' => t('Nid'),
  278. 'help' => t('The node ID to which the comment is a reply to.'),
  279. 'relationship' => array(
  280. 'title' => t('Content'),
  281. 'help' => t('The content to which the comment is a reply to.'),
  282. 'base' => 'node',
  283. 'base field' => 'nid',
  284. 'id' => 'standard',
  285. 'label' => t('Content'),
  286. ),
  287. 'filter' => array(
  288. 'id' => 'numeric',
  289. ),
  290. 'argument' => array(
  291. 'id' => 'numeric',
  292. ),
  293. 'field' => array(
  294. 'id' => 'numeric',
  295. ),
  296. );
  297. $data['comment']['uid'] = array(
  298. 'title' => t('Author uid'),
  299. 'help' => t('If you need more fields than the uid add the comment: author relationship'),
  300. 'relationship' => array(
  301. 'title' => t('Author'),
  302. 'help' => t("The User ID of the comment's author."),
  303. 'base' => 'users',
  304. 'base field' => 'uid',
  305. 'id' => 'standard',
  306. 'label' => t('author'),
  307. ),
  308. 'filter' => array(
  309. 'id' => 'numeric',
  310. ),
  311. 'argument' => array(
  312. 'id' => 'numeric',
  313. ),
  314. 'field' => array(
  315. 'id' => 'user',
  316. ),
  317. );
  318. $data['comment']['pid'] = array(
  319. 'title' => t('Parent CID'),
  320. 'help' => t('The Comment ID of the parent comment.'),
  321. 'field' => array(
  322. 'id' => 'standard',
  323. ),
  324. 'relationship' => array(
  325. 'title' => t('Parent comment'),
  326. 'help' => t('The parent comment.'),
  327. 'base' => 'comment',
  328. 'base field' => 'cid',
  329. 'id' => 'standard',
  330. 'label' => t('Parent comment'),
  331. ),
  332. );
  333. if (Drupal::moduleHandler()->moduleExists('translation_entity')) {
  334. $data['comment']['translation_link'] = array(
  335. 'title' => t('Translation link'),
  336. 'help' => t('Provide a link to the translations overview for comments.'),
  337. 'field' => array(
  338. 'id' => 'translation_entity_link',
  339. ),
  340. );
  341. }
  342. // Define the base group of this table. Fields that don't have a group defined
  343. // will go into this field by default.
  344. $data['node_comment_statistics']['table']['group'] = t('Content');
  345. // Explain how this table joins to others.
  346. $data['node_comment_statistics']['table']['join'] = array(
  347. 'node' => array(
  348. 'type' => 'INNER',
  349. 'left_field' => 'nid',
  350. 'field' => 'nid',
  351. ),
  352. );
  353. $data['node_comment_statistics']['last_comment_timestamp'] = array(
  354. 'title' => t('Last comment time'),
  355. 'help' => t('Date and time of when the last comment was posted.'),
  356. 'field' => array(
  357. 'id' => 'comment_last_timestamp',
  358. ),
  359. 'sort' => array(
  360. 'id' => 'date',
  361. ),
  362. 'filter' => array(
  363. 'id' => 'date',
  364. ),
  365. );
  366. $data['node_comment_statistics']['last_comment_name'] = array(
  367. 'title' => t("Last comment author"),
  368. 'help' => t('The name of the author of the last posted comment.'),
  369. 'field' => array(
  370. 'id' => 'comment_ncs_last_comment_name',
  371. 'no group by' => TRUE,
  372. ),
  373. 'sort' => array(
  374. 'id' => 'comment_ncs_last_comment_name',
  375. 'no group by' => TRUE,
  376. ),
  377. );
  378. $data['node_comment_statistics']['comment_count'] = array(
  379. 'title' => t('Comment count'),
  380. 'help' => t('The number of comments a node has.'),
  381. 'field' => array(
  382. 'id' => 'numeric',
  383. ),
  384. 'filter' => array(
  385. 'id' => 'numeric',
  386. ),
  387. 'sort' => array(
  388. 'id' => 'standard',
  389. ),
  390. 'argument' => array(
  391. 'id' => 'standard',
  392. ),
  393. );
  394. $data['node_comment_statistics']['last_updated'] = array(
  395. 'title' => t('Updated/commented date'),
  396. 'help' => t('The most recent of last comment posted or node updated time.'),
  397. 'field' => array(
  398. 'id' => 'comment_ncs_last_updated',
  399. 'no group by' => TRUE,
  400. ),
  401. 'sort' => array(
  402. 'id' => 'comment_ncs_last_updated',
  403. 'no group by' => TRUE,
  404. ),
  405. 'filter' => array(
  406. 'id' => 'comment_ncs_last_updated',
  407. ),
  408. );
  409. $data['node_comment_statistics']['cid'] = array(
  410. 'title' => t('Last comment CID'),
  411. 'help' => t('Display the last comment of a node'),
  412. 'relationship' => array(
  413. 'title' => t('Last comment'),
  414. 'help' => t('The last comment of a node.'),
  415. 'group' => t('Comment'),
  416. 'base' => 'comment',
  417. 'base field' => 'cid',
  418. 'id' => 'standard',
  419. 'label' => t('Last Comment'),
  420. ),
  421. );
  422. $data['node_comment_statistics']['last_comment_uid'] = array(
  423. 'title' => t('Last comment uid'),
  424. 'help' => t('The User ID of the author of the last comment of a node.'),
  425. 'relationship' => array(
  426. 'title' => t('Last comment author'),
  427. 'base' => 'users',
  428. 'base field' => 'uid',
  429. 'id' => 'standard',
  430. 'label' => t('Last comment author'),
  431. ),
  432. 'filter' => array(
  433. 'id' => 'numeric',
  434. ),
  435. 'argument' => array(
  436. 'id' => 'numeric',
  437. ),
  438. 'field' => array(
  439. 'id' => 'numeric',
  440. ),
  441. );
  442. return $data;
  443. }
  444. /**
  445. * Implements hook_views_data_alter().
  446. */
  447. function comment_views_data_alter(&$data) {
  448. // new comments
  449. $data['node']['new_comments'] = array(
  450. 'title' => t('New comments'),
  451. 'help' => t('The number of new comments on the node.'),
  452. 'field' => array(
  453. 'id' => 'node_new_comments',
  454. 'no group by' => TRUE,
  455. ),
  456. );
  457. $data['node']['comments_link'] = array(
  458. 'field' => array(
  459. 'title' => t('Add comment link'),
  460. '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.'),
  461. 'id' => 'comment_node_link',
  462. ),
  463. );
  464. $data['node_field_data']['comment'] = array(
  465. 'title' => t('Comment status'),
  466. 'help' => t('Whether comments are enabled or disabled on the node.'),
  467. 'field' => array(
  468. 'id' => 'node_comment',
  469. ),
  470. 'sort' => array(
  471. 'id' => 'standard',
  472. ),
  473. 'filter' => array(
  474. 'id' => 'node_comment',
  475. ),
  476. );
  477. $data['node_field_data']['uid_touch'] = array(
  478. 'title' => t('User posted or commented'),
  479. 'help' => t('Display nodes only if a user posted the node or commented on the node.'),
  480. 'argument' => array(
  481. 'field' => 'uid',
  482. 'name table' => 'users',
  483. 'name field' => 'name',
  484. 'id' => 'argument_comment_user_uid',
  485. 'no group by' => TRUE,
  486. ),
  487. 'filter' => array(
  488. 'field' => 'uid',
  489. 'name table' => 'users',
  490. 'name field' => 'name',
  491. 'id' => 'comment_user_uid',
  492. ),
  493. );
  494. $data['node']['cid'] = array(
  495. 'title' => t('Comments of the node'),
  496. '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.'),
  497. 'relationship' => array(
  498. 'group' => t('Comment'),
  499. 'label' => t('Comments'),
  500. 'base' => 'comment',
  501. 'base field' => 'nid',
  502. 'relationship field' => 'nid',
  503. 'id' => 'standard',
  504. ),
  505. );
  506. }
  507. /**
  508. * Implements hook_views_plugins_row_alter().
  509. *
  510. * Replaces the generic row plugin by a custom one for comments.
  511. *
  512. * @see \Drupal\views\Plugin\views\row\EntityRow
  513. */
  514. function comment_views_plugins_row_alter(array &$plugins) {
  515. $plugins['entity:comment']['class'] = 'Drupal\comment\Plugin\views\row\CommentRow';
  516. $plugins['entity:comment']['module'] = 'comment';
  517. }

Related topics

Functions