function Rss::render

Same name in this branch

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

Parameters

stdClass $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

drupal/core/modules/comment/lib/Drupal/comment/Plugin/views/row/Rss.php, line 90
Definition of Drupal\comment\Plugin\views\row\Rss.

Class

Rss
Plugin which formats the comments as RSS items.

Namespace

Drupal\comment\Plugin\views\row

Code

function render($row) {
  global $base_url;
  $cid = $row->{$this->field_alias};
  if (!is_numeric($cid)) {
    return;
  }
  $item_length = $this->options['item_length'];
  if ($item_length == 'default') {
    $item_length = config('system.rss')
      ->get('items.view_mode');
  }

  // Load the specified comment and its associated node:
  $comment = $this->comments[$cid];
  if (empty($comment)) {
    return;
  }
  $item_text = '';
  $uri = $comment
    ->uri();
  $comment->link = url($uri['path'], $uri['options'] + array(
    'absolute' => TRUE,
  ));
  $comment->rss_namespaces = array();
  $comment->rss_elements = array(
    array(
      'key' => 'pubDate',
      'value' => gmdate('r', $comment->created->value),
    ),
    array(
      'key' => 'dc:creator',
      'value' => $comment->name->value,
    ),
    array(
      'key' => 'guid',
      'value' => 'comment ' . $comment
        ->id() . ' at ' . $base_url,
      'attributes' => array(
        'isPermaLink' => 'false',
      ),
    ),
  );

  // The comment gets built and modules add to or modify
  // $comment->rss_elements and $comment->rss_namespaces.
  $build = 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);
  }

  // Hide the links if desired.
  if (!$this->options['links']) {
    hide($build['links']);
  }
  if ($item_length != 'title') {

    // We render comment contents and force links to be last.
    $build['links']['#weight'] = 1000;
    $item_text .= drupal_render($build);
  }
  $item = new \stdClass();
  $item->description = $item_text;
  $item->title = $comment
    ->label();
  $item->link = $comment->link;
  $item->elements = $comment->rss_elements;
  $item->cid = $comment
    ->id();
  return theme($this
    ->themeFunctions(), array(
    'view' => $this->view,
    'options' => $this->options,
    'row' => $item,
  ));
}