views_plugin_row_comment_view.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_plugin_row_comment_view.
  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. /**
  11. * {@inheritdoc}
  12. */
  13. public $base_field = 'cid';
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public $base_table = 'comment';
  18. /**
  19. * Stores all comments which are preloaded.
  20. */
  21. public $comments = array();
  22. /**
  23. * Stores all nodes of all comments which are preloaded.
  24. */
  25. public $nodes = array();
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function summary_title() {
  30. return t('Settings');
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function option_definition() {
  36. $options = parent::option_definition();
  37. $options['links'] = array('default' => TRUE, 'bool' => TRUE);
  38. $options['view_mode'] = array('default' => 'full');
  39. return $options;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function options_form(&$form, &$form_state) {
  45. parent::options_form($form, $form_state);
  46. $options = $this->options_form_summary_options();
  47. $form['view_mode'] = array(
  48. '#type' => 'select',
  49. '#options' => $options,
  50. '#title' => t('View mode'),
  51. '#default_value' => $this->options['view_mode'],
  52. );
  53. $form['links'] = array(
  54. '#type' => 'checkbox',
  55. '#title' => t('Display links'),
  56. '#default_value' => $this->options['links'],
  57. );
  58. }
  59. /**
  60. * Return the main options, which are shown in the summary title.
  61. */
  62. public function options_form_summary_options() {
  63. $entity_info = entity_get_info('comment');
  64. $options = array();
  65. if (!empty($entity_info['view modes'])) {
  66. foreach ($entity_info['view modes'] as $mode => $settings) {
  67. $options[$mode] = $settings['label'];
  68. }
  69. }
  70. if (empty($options)) {
  71. $options = array(
  72. 'full' => t('Full content')
  73. );
  74. }
  75. return $options;
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function pre_render($result) {
  81. $cids = array();
  82. foreach ($result as $row) {
  83. $cids[] = $row->cid;
  84. }
  85. // Load all comments.
  86. $cresult = comment_load_multiple($cids);
  87. $nids = array();
  88. foreach ($cresult as $comment) {
  89. $comment->depth = count(explode('.', $comment->thread)) - 1;
  90. $this->comments[$comment->cid] = $comment;
  91. $nids[] = $comment->nid;
  92. }
  93. // Load all nodes of the comments.
  94. $nodes = node_load_multiple(array_unique($nids));
  95. foreach ($nodes as $node) {
  96. $this->nodes[$node->nid] = $node;
  97. }
  98. }
  99. }