summaryrefslogtreecommitdiffstats
path: root/core/modules/aggregator/aggregator.theme.inc
blob: 706a01e57a03731a7c172800c99757474e85cc5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

/**
 * @file
 * Preprocessors and theme functions of Aggregator module.
 */

use Drupal\Component\Utility\String;
use Drupal\Core\Render\Element;

/**
 * Prepares variables for aggregator item templates.
 *
 * Default template: aggregator-item.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - elements: An array of elements to display in view mode.
 */
function template_preprocess_aggregator_item(&$variables) {
  $item = $variables['elements']['#aggregator_item'];

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

  $variables['url'] = check_url($item->getLink());
  $variables['title'] = String::checkPlain($item->label());
}

/**
 * Prepares variables for aggregator feed templates.
 *
 * Default template: aggregator-feed.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - elements: An array of elements to display in view mode.
 */
function template_preprocess_aggregator_feed(&$variables) {
  $feed = $variables['elements']['#aggregator_feed'];

  // Helpful $content variable for templates.
  foreach (Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }
  $variables['full'] = $variables['elements']['#view_mode'] == 'full';
  $variables['title'] = String::checkPlain($feed->label());
}

/**
 * Prepares variables for individual feed item block templates.
 *
 * Default template: aggregator-block-item.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - item: The item to be displayed.
 *   - feed: Not used.
 */
function template_preprocess_aggregator_block_item(&$variables) {
  // Display the external link to the item.
  $item = $variables['item'];
  $variables['url'] = check_url($item->getLink());
  $variables['title'] = String::checkPlain($item->label());
}