function Rss::render

Same name in this branch
  1. 10 core/modules/node/src/Plugin/views/row/Rss.php \Drupal\node\Plugin\views\row\Rss::render()
  2. 10 core/modules/views/src/Plugin/views/style/Rss.php \Drupal\views\Plugin\views\style\Rss::render()
Same name and namespace in other branches
  1. 9 core/modules/node/src/Plugin/views/row/Rss.php \Drupal\node\Plugin\views\row\Rss::render()
  2. 9 core/modules/views/src/Plugin/views/style/Rss.php \Drupal\views\Plugin\views\style\Rss::render()
  3. 9 core/modules/aggregator/src/Plugin/views/row/Rss.php \Drupal\aggregator\Plugin\views\row\Rss::render()
  4. 9 core/modules/comment/src/Plugin/views/row/Rss.php \Drupal\comment\Plugin\views\row\Rss::render()
  5. 8.9.x core/modules/node/src/Plugin/views/row/Rss.php \Drupal\node\Plugin\views\row\Rss::render()
  6. 8.9.x core/modules/views/src/Plugin/views/style/Rss.php \Drupal\views\Plugin\views\style\Rss::render()
  7. 8.9.x core/modules/aggregator/src/Plugin/views/row/Rss.php \Drupal\aggregator\Plugin\views\row\Rss::render()
  8. 8.9.x core/modules/comment/src/Plugin/views/row/Rss.php \Drupal\comment\Plugin\views\row\Rss::render()
  9. 11.x core/modules/node/src/Plugin/views/row/Rss.php \Drupal\node\Plugin\views\row\Rss::render()
  10. 11.x core/modules/views/src/Plugin/views/style/Rss.php \Drupal\views\Plugin\views\style\Rss::render()
  11. 11.x core/modules/comment/src/Plugin/views/row/Rss.php \Drupal\comment\Plugin\views\row\Rss::render()

Renders a row object.

This usually passes through to a theme template of some form, but not always.

Parameters

object $row: A single row of the query result, so an element of $view->result.

Return value

string The rendered output of a single row, used by the style plugin.

Overrides RowPluginBase::render

File

core/modules/comment/src/Plugin/views/row/Rss.php, line 71

Class

Rss
Plugin which formats the comments as RSS items.

Namespace

Drupal\comment\Plugin\views\row

Code

public function render($row) {
  global $base_url;
  $cid = $row->{$this->field_alias};
  if (!is_numeric($cid)) {
    return;
  }
  $view_mode = $this->options['view_mode'];
  if ($view_mode == 'default') {
    $view_mode = \Drupal::config('system.rss')->get('items.view_mode');
  }
  // Load the specified comment and its associated node:
  /** @var \Drupal\comment\CommentInterface $comment */
  $comment = $this->comments[$cid];
  if (empty($comment)) {
    return;
  }
  $comment->rss_namespaces = [];
  $comment->rss_elements = [
    [
      'key' => 'pubDate',
      'value' => gmdate('r', $comment->getCreatedTime()),
    ],
    [
      'key' => 'dc:creator',
      'value' => $comment->getAuthorName(),
    ],
    [
      'key' => 'guid',
      'value' => 'comment ' . $comment->id() . ' at ' . $base_url,
      'attributes' => [
        'isPermaLink' => 'false',
      ],
    ],
  ];
  // The comment gets built and modules add to or modify
  // $comment->rss_elements and $comment->rss_namespaces.
  $build = $this->entityTypeManager
    ->getViewBuilder('comment')
    ->view($comment, 'rss');
  unset($build['#theme']);
  if (!empty($comment->rss_namespaces)) {
    $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $comment->rss_namespaces);
  }
  $item = new \stdClass();
  if ($view_mode != 'title') {
    // We render comment contents.
    $item->description = $build;
  }
  $item->title = $comment->label();
  $item->link = $comment->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString();
  // Provide a reference so that the render call in
  // template_preprocess_views_view_row_rss() can still access it.
  $item->elements =& $comment->rss_elements;
  $item->cid = $comment->id();
  $build = [
    '#theme' => $this->themeFunctions(),
    '#view' => $this->view,
    '#options' => $this->options,
    '#row' => $item,
  ];
  return $build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.