You are here

function template_preprocess_views_view_googlenews in Views Google News 8

Prepares variables for GoogleNews feed templates.

Default template: views-view-googlenews.html.twig.

Parameters

array $variables: An associative array containing:

  • view: A ViewExecutable object.
  • rows: The raw row data.

File

./views_googlenews.module, line 20
Views Google News module bootstrap file.

Code

function template_preprocess_views_view_googlenews(array &$variables) {
  $config = \Drupal::config('system.site');
  $name = $config
    ->get('name');
  $items = $variables['rows'];
  foreach ($items as &$item) {
    if (empty($item['#row']['news_publication_name'])) {
      $item['#row']['news_publication_name'] = $name;
    }
    if (empty($item['#row']['news_publication_language'])) {
      $item['#row']['news_publication_language'] = \Drupal::languageManager()
        ->getDefaultLanguage()
        ->getId();
    }
  }
  $variables['items'] = $items;

  // During live preview we don't want to output the header since the contents
  // of the feed are being displayed inside a normal HTML page.
  if (empty($variables['view']->live_preview)) {
    $variables['view']
      ->getResponse()->headers
      ->set('Content-Type', 'text/xml; charset=utf-8');
  }
}