3 namespace Drupal\comment\Plugin\views\row;
5 use Drupal\views\Plugin\views\row\RssPluginBase;
8 * Plugin which formats the comments as RSS items.
12 * title = @Translation("Comment"),
13 * help = @Translation("Display the comment as RSS."),
14 * theme = "views_view_row_rss",
15 * register_theme = FALSE,
16 * base = {"comment_field_data"},
17 * display_types = {"feed"}
20 class Rss extends RssPluginBase {
25 protected $base_table = 'comment_field_data';
30 protected $base_field = 'cid';
33 * @var \Drupal\comment\CommentInterface[]
40 protected $entityTypeId = 'comment';
42 public function preRender($result) {
45 foreach ($result as $row) {
49 $this->comments = $this->entityManager->getStorage('comment')->loadMultiple($cids);
55 public function buildOptionsForm_summary_options() {
56 $options = parent::buildOptionsForm_summary_options();
57 $options['title'] = $this->t('Title only');
58 $options['default'] = $this->t('Use site default RSS settings');
62 public function render($row) {
65 $cid = $row->{$this->field_alias};
66 if (!is_numeric($cid)) {
70 $view_mode = $this->options['view_mode'];
71 if ($view_mode == 'default') {
72 $view_mode = \Drupal::config('system.rss')->get('items.view_mode');
75 // Load the specified comment and its associated node:
76 /** @var $comment \Drupal\comment\CommentInterface */
77 $comment = $this->comments[$cid];
78 if (empty($comment)) {
82 $comment->link = $comment->url('canonical', ['absolute' => TRUE]);
83 $comment->rss_namespaces = [];
84 $comment->rss_elements = [
87 'value' => gmdate('r', $comment->getCreatedTime()),
90 'key' => 'dc:creator',
91 'value' => $comment->getAuthorName(),
95 'value' => 'comment ' . $comment->id() . ' at ' . $base_url,
96 'attributes' => ['isPermaLink' => 'false'],
100 // The comment gets built and modules add to or modify
101 // $comment->rss_elements and $comment->rss_namespaces.
102 $build = $this->entityManager->getViewBuilder('comment')->view($comment, 'rss');
103 unset($build['#theme']);
105 if (!empty($comment->rss_namespaces)) {
106 $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $comment->rss_namespaces);
109 $item = new \stdClass();
110 if ($view_mode != 'title') {
111 // We render comment contents.
112 $item->description = $build;
114 $item->title = $comment->label();
115 $item->link = $comment->link;
116 // Provide a reference so that the render call in
117 // template_preprocess_views_view_row_rss() can still access it.
118 $item->elements = &$comment->rss_elements;
119 $item->cid = $comment->id();
122 '#theme' => $this->themeFunctions(),
123 '#view' => $this->view,
124 '#options' => $this->options,