You are here

function template_preprocess_sitemap_feed_icon in Sitemap 8

Preprocesses variables for sitemap-feed-icon.html.twig.

Parameters

array $variables: An associative array containing:

  • url: The url of the feed.
  • name: The name of the feed.
  • type: The type of feed icon.

File

./sitemap.theme.inc, line 21
Sitemap theme functions.

Code

function template_preprocess_sitemap_feed_icon(array &$variables) {
  $output = '';
  switch ($variables['type']) {
    case 'node':
      $image = [
        '#theme' => 'image',
        '#uri' => drupal_get_path('module', 'sitemap') . '/images/feed-small.png',
        '#title' => t('Syndicated feed icon'),
        '#alt' => t('Syndicated feed icon'),
      ];
      $output = \Drupal::service('renderer')
        ->render($image);
      break;
  }
  if (!empty($variables['url'])) {
    $output = Link::fromTextAndUrl($output, Url::fromUri('base://' . $variables['url'], [
      'attributes' => [
        'class' => 'feed-link',
        'title' => t('Syndicated feed for @feed_name', [
          '@feed_name' => $variables['name'],
        ]),
      ],
      'html' => TRUE,
    ]))
      ->toString();
  }
  $variables['icon'] = $output;
}