diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 1a5ed47..1c2158d 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -144,9 +144,7 @@ function aggregator_menu() { ); $items['aggregator/sources'] = array( 'title' => 'Sources', - 'page callback' => 'aggregator_page_sources', - 'access arguments' => array('access news feeds'), - 'file' => 'aggregator.pages.inc', + 'route_name' => 'aggregator_sources', ); $items['aggregator/categories'] = array( 'title' => 'Categories', diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index 6248012..9f5fe67 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -328,46 +328,6 @@ function template_preprocess_aggregator_item(&$variables) { } /** - * Page callback: Displays all the feeds used by the Aggregator module. - * - * @return string - * An HTML-formatted string. - * - * @see aggregator_menu() - */ -function aggregator_page_sources() { - $feeds = entity_load_multiple('aggregator_feed'); - - $build = array( - '#type' => 'container', - '#attributes' => array('class' => array('aggregator-wrapper')), - '#sorted' => TRUE, - ); - foreach ($feeds as $feed) { - // Most recent items: - $summary_items = array(); - $aggregator_summary_items = config('aggregator.settings')->get('source.list_max'); - if ($aggregator_summary_items) { - if ($items = aggregator_load_feed_items('source', $feed, $aggregator_summary_items)) { - $summary_items = entity_view_multiple($items, 'summary'); - } - } - $feed->url = url('aggregator/sources/' . $feed->id()); - $build[$feed->id()] = array( - '#theme' => 'aggregator_summary_items', - '#summary_items' => $summary_items, - '#source' => $feed, - ); - } - $build['feed_icon'] = array( - '#theme' => 'feed_icon', - '#url' => 'aggregator/opml', - '#title' => t('OPML feed'), - ); - return $build; -} - -/** * Page callback: Displays all the categories used by the Aggregator module. * * @return string diff --git a/core/modules/aggregator/aggregator.routing.yml b/core/modules/aggregator/aggregator.routing.yml index c41cf0e..bcd7d25 100644 --- a/core/modules/aggregator/aggregator.routing.yml +++ b/core/modules/aggregator/aggregator.routing.yml @@ -39,3 +39,10 @@ aggregator_opml_add: _form: '\Drupal\aggregator\Form\OpmlFeedAdd' requirements: _permission: 'administer news feeds' + +aggregator_sources: + pattern: 'aggregator/sources' + defaults: + _content: '\Drupal\aggregator\Routing\AggregatorController::sources' + requirements: + _permission: 'access news feeds' diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php b/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php index ff2b222..8badecc 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php @@ -8,6 +8,7 @@ namespace Drupal\aggregator\Routing; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Config\ConfigFactory; use Drupal\Core\ControllerInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManager; @@ -25,6 +26,13 @@ class AggregatorController implements ControllerInterface { protected $entityManager; /** + * The configuration factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** * The database connection. * * @var \Drupal\Core\Database\Connection; @@ -36,11 +44,14 @@ class AggregatorController implements ControllerInterface { * * @param \Drupal\Core\Entity\EntityManager $entity_manager * The Entity manager. + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The config factory. * @param \Drupal\Core\Database\Connection $database * The database connection. */ - public function __construct(EntityManager $entity_manager, Connection $database) { + public function __construct(EntityManager $entity_manager, ConfigFactory $config_factory, Connection $database) { $this->entityManager = $entity_manager; + $this->configFactory = $config_factory; $this->database = $database; } @@ -50,6 +61,7 @@ public function __construct(EntityManager $entity_manager, Connection $database) public static function create(ContainerInterface $container) { return new static( $container->get('plugin.manager.entity'), + $container->get('config.factory'), $container->get('database') ); } @@ -153,4 +165,50 @@ public function adminOverview() { return $build; } + /** + * Displays all the feeds used by the Aggregator module. + * + * @return array + * A render array as expected by drupal_render(). + */ + public function sources() { + + $feeds = $this->entityManager->getStorageController('aggregator_feed')->load(); + + // @todo remove this once all callbacks are converted. + module_load_include('inc', 'aggregator', 'aggregator.pages'); + + $build = array( + '#type' => 'container', + '#attributes' => array('class' => array('aggregator-wrapper')), + '#sorted' => TRUE, + ); + foreach ($feeds as $feed) { + // Most recent items: + $summary_items = array(); + $aggregator_summary_items = $this->configFactory + ->get('aggregator.settings') + ->get('source.list_max'); + if ($aggregator_summary_items) { + if ($items = aggregator_load_feed_items('source', $feed, $aggregator_summary_items)) { + $summary_items = $this->entityManager + ->getRenderController('aggregator_item') + ->viewMultiple($items, 'summary'); + } + } + $feed->url = url('aggregator/sources/' . $feed->id()); + $build[$feed->id()] = array( + '#theme' => 'aggregator_summary_items', + '#summary_items' => $summary_items, + '#source' => $feed, + ); + } + $build['feed_icon'] = array( + '#theme' => 'feed_icon', + '#url' => 'aggregator/opml', + '#title' => t('OPML feed'), + ); + return $build; + } + }