You are here

function template_preprocess_feeds_feed in Feeds 8.3

Prepares variables for feed templates.

Default template: feeds_feed.html.twig.

Most themes utilize their own copy of feeds_feed.html.twig. The default is located inside "modules/feeds/templates/feeds_feed.html.twig". Look in there for the full list of variables.

Parameters

array $variables: An associative array containing:

  • elements: An array of elements to display in view mode.
  • feed: The feed object.
  • view_mode: View mode; e.g., 'full', 'teaser'...

File

./feeds.module, line 241
Feeds hook implementations.

Code

function template_preprocess_feeds_feed(array &$variables) {
  $variables['view_mode'] = $variables['elements']['#view_mode'];
  $variables['feed'] = $feed = $variables['elements']['#feeds_feed'];
  $variables['page'] = $variables['view_mode'] === 'full';
  $variables['date'] = \Drupal::service('renderer')
    ->render($variables['elements']['created']);
  unset($variables['elements']['created']);
  $variables['author_name'] = \Drupal::service('renderer')
    ->render($variables['elements']['uid']);
  unset($variables['elements']['uid']);
  $variables['url'] = $feed
    ->toUrl('canonical', [
    'language' => $feed
      ->language(),
  ]);
  $variables['label'] = $variables['elements']['title'];
  unset($variables['elements']['title']);

  // Helpful $content variable for templates.
  $variables += [
    'content' => [],
  ];
  foreach (Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }

  // Used by RDF to add attributes around the author and date submitted.
  $variables['author_attributes'] = new Attribute();

  // Add article ARIA role.
  $variables['attributes']['role'] = 'article';
}