views_plugin_row_comment_view.inc

  1. 3.x modules/comment/views_plugin_row_comment_view.inc
  2. 2.x modules/comment/views_plugin_row_comment_view.inc

Contains the node RSS row style plugin.

File

modules/comment/views_plugin_row_comment_view.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains the node RSS row style plugin.
  5. */
  6. /**
  7. * Plugin which performs a comment_view on the resulting object.
  8. */
  9. class views_plugin_row_comment_view extends views_plugin_row {
  10. var $base_field = 'cid';
  11. var $base_table = 'comment';
  12. /**
  13. * Stores all comments which are preloaded.
  14. */
  15. var $comments = array();
  16. /**
  17. * Stores all nodes of all comments which are preloaded.
  18. */
  19. var $nodes = array();
  20. function summary_title() {
  21. return t('Settings');
  22. }
  23. function option_definition() {
  24. $options = parent::option_definition();
  25. $options['links'] = array('default' => TRUE, 'bool' => TRUE);
  26. $options['view_mode'] = array('default' => 'full');
  27. return $options;
  28. }
  29. function options_form(&$form, &$form_state) {
  30. parent::options_form($form, $form_state);
  31. $options = $this->options_form_summary_options();
  32. $form['view_mode'] = array(
  33. '#type' => 'select',
  34. '#options' => $options,
  35. '#title' => t('View mode'),
  36. '#default_value' => $this->options['view_mode'],
  37. );
  38. $form['links'] = array(
  39. '#type' => 'checkbox',
  40. '#title' => t('Display links'),
  41. '#default_value' => $this->options['links'],
  42. );
  43. }
  44. /**
  45. * Return the main options, which are shown in the summary title.
  46. */
  47. function options_form_summary_options() {
  48. $entity_info = entity_get_info('comment');
  49. $options = array();
  50. if (!empty($entity_info['view modes'])) {
  51. foreach ($entity_info['view modes'] as $mode => $settings) {
  52. $options[$mode] = $settings['label'];
  53. }
  54. }
  55. if (empty($options)) {
  56. $options = array(
  57. 'full' => t('Full content')
  58. );
  59. }
  60. return $options;
  61. }
  62. function pre_render($result) {
  63. $cids = array();
  64. foreach ($result as $row) {
  65. $cids[] = $row->cid;
  66. }
  67. // Load all comments.
  68. $cresult = comment_load_multiple($cids);
  69. $nids = array();
  70. foreach ($cresult as $comment) {
  71. $comment->depth = count(explode('.', $comment->thread)) - 1;
  72. $this->comments[$comment->cid] = $comment;
  73. $nids[] = $comment->nid;
  74. }
  75. // Load all nodes of the comments.
  76. $nodes = node_load_multiple(array_unique($nids));
  77. foreach ($nodes as $node) {
  78. $this->nodes[$node->nid] = $node;
  79. }
  80. }
  81. }