From edd8fd804f5a647a9c5f6ab4bf85bbb6be997b93 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Thu, 13 Feb 2014 10:17:50 +0000
Subject: [PATCH] Issue #2138115 by InternetDevels, ParisLiakos: Split
 aggregator theme functions to a separate file.

---
 core/modules/aggregator/aggregator.module    |  29 +--
 core/modules/aggregator/aggregator.pages.inc | 169 -----------------
 core/modules/aggregator/aggregator.theme.inc | 190 +++++++++++++++++++
 3 files changed, 197 insertions(+), 191 deletions(-)
 create mode 100644 core/modules/aggregator/aggregator.theme.inc

diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module
index 0ce31c2e0716..712dfad90845 100644
--- a/core/modules/aggregator/aggregator.module
+++ b/core/modules/aggregator/aggregator.module
@@ -53,35 +53,36 @@ function aggregator_theme() {
   return array(
     'aggregator_feed_source' => array(
       'variables' => array('aggregator_feed' => NULL, 'view_mode' => NULL),
-      'file' => 'aggregator.pages.inc',
+      'file' => 'aggregator.theme.inc',
       'template' => 'aggregator-feed-source',
     ),
     'aggregator_block_item' => array(
       'variables' => array('item' => NULL, 'feed' => 0),
+      'file' => 'aggregator.theme.inc',
       'template' => 'aggregator-block-item',
     ),
     'aggregator_summary_items' => array(
       'variables' => array('summary_items' => NULL, 'source' => NULL),
-      'file' => 'aggregator.pages.inc',
+      'file' => 'aggregator.theme.inc',
       'template' => 'aggregator-summary-items',
     ),
     'aggregator_summary_item' => array(
       'variables' => array('aggregator_item' => NULL, 'view_mode' => NULL),
-      'file' => 'aggregator.pages.inc',
+      'file' => 'aggregator.theme.inc',
       'template' => 'aggregator-summary-item',
     ),
     'aggregator_item' => array(
       'variables' => array('aggregator_item' => NULL, 'view_mode' => NULL),
-      'file' => 'aggregator.pages.inc',
+      'file' => 'aggregator.theme.inc',
       'template' => 'aggregator-item',
     ),
     'aggregator_page_opml' => array(
       'variables' => array('feeds' => NULL),
-      'file' => 'aggregator.pages.inc',
+      'file' => 'aggregator.theme.inc',
     ),
     'aggregator_page_rss' => array(
       'variables' => array('feeds' => NULL),
-      'file' => 'aggregator.pages.inc',
+      'file' => 'aggregator.theme.inc',
     ),
   );
 }
@@ -306,22 +307,6 @@ function aggregator_feed_load($fid) {
   return entity_load('aggregator_feed', $fid);
 }
 
-/**
- * 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.
-  $variables['url'] = check_url($variables['item']->link);
-  $variables['title'] = check_plain($variables['item']->title);
-}
-
 /**
  * Renders the HTML content safely, as allowed.
  *
diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc
index 010a9d7512a7..95b6f6f7c64d 100644
--- a/core/modules/aggregator/aggregator.pages.inc
+++ b/core/modules/aggregator/aggregator.pages.inc
@@ -5,9 +5,6 @@
  * User page callbacks for the Aggregator module.
  */
 
-use Drupal\aggregator\Entity\Feed;
-use Drupal\Core\Entity\EntityInterface;
-
 /**
  * Loads and optionally filters feed items.
  *
@@ -40,169 +37,3 @@ function aggregator_load_feed_items($type, $data = NULL, $limit = 20) {
       return $storage_controller->loadByFeed($data->id(), $limit);
   }
 }
-
-/**
- * Prepares variables for aggregator item templates.
- *
- * Default template: aggregator-item.html.twig.
- *
- * @param array $variables
- *   An associative array containing:
- *   - aggregator_item: An individual feed item for display on the aggregator
- *     page.
- */
-function template_preprocess_aggregator_item(&$variables) {
-  $item = $variables['aggregator_item'];
-
-  $variables['feed_url'] = check_url($item->getLink());
-  $variables['feed_title'] = check_plain($item->getTitle());
-  $variables['content'] = aggregator_filter_xss($item->getDescription());
-
-  $variables['source_url'] = '';
-  $variables['source_title'] = '';
-  $fid = $item->getFeedId();
-  if (isset($item->ftitle) && $fid !== NULL) {
-    $variables['source_url'] = url('aggregator/sources/' . $fid);
-    $variables['source_title'] = check_plain($item->ftitle);
-  }
-  if (date('Ymd', $item->getPostedTime()) == date('Ymd')) {
-    $variables['source_date'] = t('%ago ago', array('%ago' => format_interval(REQUEST_TIME - $item->getPostedTime())));
-  }
-  else {
-    $variables['source_date'] = format_date($item->getPostedTime(), 'medium');
-  }
-
-  $variables['attributes']['class'][] = 'feed-item';
-}
-
-/**
- * Prints the OPML page for the feed.
- *
- * @param array $variables
- *   An associative array containing:
- *   - feeds: An array of the feeds to theme.
- *
- * @return string
- *   An OPML formatted string.
- *
- * @ingroup themeable
- */
-function theme_aggregator_page_opml($variables) {
-  $feeds = $variables['feeds'];
-
-  $output  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
-  $output .= "<opml version=\"1.1\">\n";
-  $output .= "<head>\n";
-  $output .= '<title>' . check_plain(\Drupal::config('system.site')->get('name')) . "</title>\n";
-  $output .= '<dateModified>' . gmdate(DATE_RFC2822, REQUEST_TIME) . "</dateModified>\n";
-  $output .= "</head>\n";
-  $output .= "<body>\n";
-  foreach ($feeds as $feed) {
-    $output .= '<outline text="' . check_plain($feed->title) . '" xmlUrl="' . check_url($feed->url) . "\" />\n";
-  }
-  $output .= "</body>\n";
-  $output .= "</opml>\n";
-
-  return $output;
-}
-
-/**
- * Prepares variables for aggregator summary templates.
- *
- * Default template: aggregator-summary-items.html.twig.
- *
- * @param array $variables
- *   An associative array containing:
- *   - source: A Drupal\aggregator\Entity\Feed instance representing
- *     the feed source.
- *   - summary_items: An array of feed items.
- */
-function template_preprocess_aggregator_summary_items(&$variables) {
-  $variables['title'] = check_plain($variables['source'] instanceof EntityInterface ? $variables['source']->label() : $variables['source']->title);
-  $summary_items = array();
-  foreach (element_children($variables['summary_items']) as $key) {
-    $summary_items[] = $variables['summary_items'][$key];
-  }
-  $variables['summary_list'] = array(
-    '#theme' => 'item_list',
-    '#items' => $summary_items,
-  );
-  $variables['source_url'] = $variables['source'] instanceof EntityInterface ? $variables['source']->url->value : $variables['source']->url;
-}
-
-/**
- * Processes variables for aggregator summary item templates.
- *
- * Default template: aggregator-summary-item.html.twig.
- *
- * @param array $variables
- *   An associative array containing:
- *   - aggregator_item: The feed item.
- *   - view_mode: How the item is being displayed.
- */
-function template_preprocess_aggregator_summary_item(&$variables) {
-  $item = $variables['aggregator_item'];
-
-  $variables['url'] = l(check_plain($item->label()), check_url(url($item->getLink(), array('absolute' => TRUE))), array(
-    'attributes' => array(
-      'class' => array('feed-item-url'),
-    ),
-  ));
-  $variables['age'] = array(
-    '#theme' => 'datetime',
-    '#attributes' => array(
-      'datetime' => format_date($item->getPostedTime(), 'html_datetime', '', 'UTC'),
-      'class' => array('feed-item-age',),
-    ),
-    '#text' => t('%age old', array('%age' => format_interval(REQUEST_TIME - $item->getPostedTime()))),
-    '#html' => TRUE,
-  );
-}
-
-/**
- * Prepares variables for aggregator feed source templates.
- *
- * Default template: aggregator-feed-source.html.twig.
- *
- * @param array $variables
- *   An associative array containing:
- *   - aggregator_feed: A Drupal\aggregator\Entity\Feed instance
- *     representing the feed source.
- */
-function template_preprocess_aggregator_feed_source(&$variables) {
-  $feed = $variables['aggregator_feed'];
-
-  $feed_icon = array(
-    '#theme' => 'feed_icon',
-    '#url' => $feed->getUrl(),
-    '#title' => t('!title feed', array('!title' => $feed->label())),
-  );
-  $variables['source_icon'] = drupal_render($feed_icon);
-
-  if ($feed->getImage() && $feed->label() && $feed->getWebsiteUrl()) {
-    $image = array(
-      '#theme' => 'image',
-      '#path' => $feed->getImage(),
-      '#alt' => $feed->label(),
-    );
-    $variables['source_image'] = l($image, $feed->getWebsiteUrl(), array('html' => TRUE, 'attributes' => array('class' => 'feed-image')));
-  }
-  else {
-    $variables['source_image'] = '';
-  }
-  $variables['source_description'] = aggregator_filter_xss($feed->getDescription());
-  $variables['source_url'] = check_url(url($feed->getWebsiteUrl(), array('absolute' => TRUE)));
-
-  if ($feed->checked) {
-    $variables['last_checked'] = t('@time ago', array('@time' => format_interval(REQUEST_TIME - $feed->getLastCheckedTime())));
-  }
-  else {
-    $variables['last_checked'] = t('never');
-  }
-
-  if (\Drupal::currentUser()->hasPermission('administer news feeds')) {
-    $variables['last_checked'] = l($variables['last_checked'], 'admin/config/services/aggregator');
-  }
-
-  $variables['attributes']['class'][] = 'feed-source';
-}
diff --git a/core/modules/aggregator/aggregator.theme.inc b/core/modules/aggregator/aggregator.theme.inc
new file mode 100644
index 000000000000..5531dd6a2f4b
--- /dev/null
+++ b/core/modules/aggregator/aggregator.theme.inc
@@ -0,0 +1,190 @@
+<?php
+
+/**
+ * @file
+ * Preprocessors and theme functions of Aggregator module.
+ */
+
+use Drupal\Core\Entity\EntityInterface;
+
+/**
+ * Prepares variables for aggregator item templates.
+ *
+ * Default template: aggregator-item.html.twig.
+ *
+ * @param array $variables
+ *   An associative array containing:
+ *   - aggregator_item: An individual feed item for display on the aggregator
+ *     page.
+ */
+function template_preprocess_aggregator_item(&$variables) {
+  $item = $variables['aggregator_item'];
+
+  $variables['feed_url'] = check_url($item->getLink());
+  $variables['feed_title'] = check_plain($item->getTitle());
+  $variables['content'] = aggregator_filter_xss($item->getDescription());
+
+  $variables['source_url'] = '';
+  $variables['source_title'] = '';
+  $fid = $item->getFeedId();
+  if (isset($item->ftitle) && $fid !== NULL) {
+    $variables['source_url'] = url('aggregator/sources/' . $fid);
+    $variables['source_title'] = check_plain($item->ftitle);
+  }
+  if (date('Ymd', $item->getPostedTime()) == date('Ymd')) {
+    $variables['source_date'] = t('%ago ago', array('%ago' => format_interval(REQUEST_TIME - $item->getPostedTime())));
+  }
+  else {
+    $variables['source_date'] = format_date($item->getPostedTime(), 'medium');
+  }
+
+  $variables['attributes']['class'][] = 'feed-item';
+}
+
+/**
+ * Prints the OPML page for the feed.
+ *
+ * @param array $variables
+ *   An associative array containing:
+ *   - feeds: An array of the feeds to theme.
+ *
+ * @return string
+ *   An OPML formatted string.
+ *
+ * @ingroup themeable
+ */
+function theme_aggregator_page_opml($variables) {
+  $feeds = $variables['feeds'];
+
+  $output  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
+  $output .= "<opml version=\"1.1\">\n";
+  $output .= "<head>\n";
+  $output .= '<title>' . check_plain(\Drupal::config('system.site')->get('name')) . "</title>\n";
+  $output .= '<dateModified>' . gmdate(DATE_RFC2822, REQUEST_TIME) . "</dateModified>\n";
+  $output .= "</head>\n";
+  $output .= "<body>\n";
+  foreach ($feeds as $feed) {
+    $output .= '<outline text="' . check_plain($feed->title) . '" xmlUrl="' . check_url($feed->url) . "\" />\n";
+  }
+  $output .= "</body>\n";
+  $output .= "</opml>\n";
+
+  return $output;
+}
+
+/**
+ * Prepares variables for aggregator summary templates.
+ *
+ * Default template: aggregator-summary-items.html.twig.
+ *
+ * @param array $variables
+ *   An associative array containing:
+ *   - source: A Drupal\aggregator\Entity\Feed instance representing
+ *     the feed source.
+ *   - summary_items: An array of feed items.
+ */
+function template_preprocess_aggregator_summary_items(&$variables) {
+  $variables['title'] = check_plain($variables['source'] instanceof EntityInterface ? $variables['source']->label() : $variables['source']->title);
+  $summary_items = array();
+  foreach (element_children($variables['summary_items']) as $key) {
+    $summary_items[] = $variables['summary_items'][$key];
+  }
+  $variables['summary_list'] = array(
+    '#theme' => 'item_list',
+    '#items' => $summary_items,
+  );
+  $variables['source_url'] = $variables['source'] instanceof EntityInterface ? $variables['source']->url->value : $variables['source']->url;
+}
+
+/**
+ * Processes variables for aggregator summary item templates.
+ *
+ * Default template: aggregator-summary-item.html.twig.
+ *
+ * @param array $variables
+ *   An associative array containing:
+ *   - aggregator_item: The feed item.
+ *   - view_mode: How the item is being displayed.
+ */
+function template_preprocess_aggregator_summary_item(&$variables) {
+  $item = $variables['aggregator_item'];
+
+  $variables['url'] = l(check_plain($item->label()), check_url(url($item->getLink(), array('absolute' => TRUE))), array(
+    'attributes' => array(
+      'class' => array('feed-item-url'),
+    ),
+  ));
+  $variables['age'] = array(
+    '#theme' => 'datetime',
+    '#attributes' => array(
+      'datetime' => format_date($item->getPostedTime(), 'html_datetime', '', 'UTC'),
+      'class' => array('feed-item-age',),
+    ),
+    '#text' => t('%age old', array('%age' => format_interval(REQUEST_TIME - $item->getPostedTime()))),
+    '#html' => TRUE,
+  );
+}
+
+/**
+ * Prepares variables for aggregator feed source templates.
+ *
+ * Default template: aggregator-feed-source.html.twig.
+ *
+ * @param array $variables
+ *   An associative array containing:
+ *   - aggregator_feed: A Drupal\aggregator\Entity\Feed instance
+ *     representing the feed source.
+ */
+function template_preprocess_aggregator_feed_source(&$variables) {
+  $feed = $variables['aggregator_feed'];
+
+  $feed_icon = array(
+    '#theme' => 'feed_icon',
+    '#url' => $feed->getUrl(),
+    '#title' => t('!title feed', array('!title' => $feed->label())),
+  );
+  $variables['source_icon'] = drupal_render($feed_icon);
+
+  if ($feed->getImage() && $feed->label() && $feed->getWebsiteUrl()) {
+    $image = array(
+      '#theme' => 'image',
+      '#path' => $feed->getImage(),
+      '#alt' => $feed->label(),
+    );
+    $variables['source_image'] = l($image, $feed->getWebsiteUrl(), array('html' => TRUE, 'attributes' => array('class' => 'feed-image')));
+  }
+  else {
+    $variables['source_image'] = '';
+  }
+  $variables['source_description'] = aggregator_filter_xss($feed->getDescription());
+  $variables['source_url'] = check_url(url($feed->getWebsiteUrl(), array('absolute' => TRUE)));
+
+  if ($feed->checked) {
+    $variables['last_checked'] = t('@time ago', array('@time' => format_interval(REQUEST_TIME - $feed->getLastCheckedTime())));
+  }
+  else {
+    $variables['last_checked'] = t('never');
+  }
+
+  if (\Drupal::currentUser()->hasPermission('administer news feeds')) {
+    $variables['last_checked'] = l($variables['last_checked'], 'admin/config/services/aggregator');
+  }
+
+  $variables['attributes']['class'][] = 'feed-source';
+}
+
+/**
+ * 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.
+  $variables['url'] = check_url($variables['item']->link);
+  $variables['title'] = check_plain($variables['item']->title);
+}
-- 
GitLab