You are here

function Rss::render in Views (for Drupal 7) 8.3

Same name in this branch
  1. 8.3 lib/Views/node/Plugin/views/row/Rss.php \Views\node\Plugin\views\row\Rss::render()
  2. 8.3 lib/Views/comment/Plugin/views/row/Rss.php \Views\comment\Plugin\views\row\Rss::render()
  3. 8.3 lib/Views/aggregator/Plugin/views/row/Rss.php \Views\aggregator\Plugin\views\row\Rss::render()
  4. 8.3 lib/Drupal/views/Plugin/views/style/Rss.php \Drupal\views\Plugin\views\style\Rss::render()

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

lib/Views/comment/Plugin/views/row/Rss.php, line 94
Definition of Views\comment\Plugin\views\row\Rss.

Class

Rss
Plugin which formats the comments as RSS items.

Namespace

Views\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) || empty($this->nodes[$comment->nid])) {
    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),
    ),
    array(
      'key' => 'dc:creator',
      'value' => $comment->name,
    ),
    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, $this->nodes[$comment->nid], '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,
  ));
}