You are here

public function GoogleNewsFields::render in Views Google News 8

Render 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

src/Plugin/views/row/GoogleNewsFields.php, line 141

Class

GoogleNewsFields
Renders an GoogleNews item based on fields.

Namespace

Drupal\views_googlenews\Plugin\views\row

Code

public function render($row) {

  // Create the Google News item array.
  $item = [];
  $row_index = $this->view->row_index;
  $item['loc'] = $this
    ->getField($row_index, $this->options['loc_field']);
  $item['news_publication_name'] = $this
    ->getField($row_index, $this->options['news_publication_name_field']);
  $item['news_publication_language'] = $this
    ->getField($row_index, $this->options['news_publication_language_field']);
  if ($this->options['news_access_field']) {
    $item['news_access'] = $this
      ->getField($row_index, $this->options['news_access_field']);
  }
  if ($this->options['news_genres_field']) {
    $item['news_genres'] = $this
      ->getField($row_index, $this->options['news_genres_field']);
  }
  $item['news_publication_date'] = $this
    ->getField($row_index, $this->options['news_publication_date_field']);
  $item['news_title'] = $this
    ->getField($row_index, $this->options['news_title_field']);
  if ($this->options['news_keywords_field']) {
    $item['news_keywords'] = $this
      ->getField($row_index, $this->options['news_keywords_field']);
  }
  if ($this->options['news_stock_tickers_field']) {
    $item['news_stock_tickers'] = $this
      ->getField($row_index, $this->options['news_stock_tickers_field']);
  }

  // Remove empty attributes.
  $item = array_filter($item);
  $build = [
    '#theme' => $this
      ->themeFunctions(),
    '#view' => $this->view,
    '#options' => $this->options,
    '#row' => $item,
    '#field_alias' => isset($this->field_alias) ? $this->field_alias : '',
  ];
  return $build;
}