diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 5021e57..bd65f4f 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -134,10 +134,8 @@ function aggregator_menu() { ); $items['aggregator'] = array( 'title' => 'Feed aggregator', - 'page callback' => 'aggregator_page_last', - 'access arguments' => array('access news feeds'), 'weight' => 5, - 'file' => 'aggregator.pages.inc', + 'route_name' => 'aggregator_page_last', ); $items['aggregator/sources'] = array( 'title' => 'Sources', diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index 6248012..10ba125 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -9,22 +9,6 @@ use Drupal\Core\Entity\EntityInterface; /** - * Page callback: Displays the most recent items gathered from any feed. - * - * @return string - * The rendered list of items for the feed. - * - * @see aggregator_menu() - */ -function aggregator_page_last() { - drupal_add_feed('aggregator/rss', config('system.site')->get('name') . ' ' . t('aggregator')); - - $items = aggregator_load_feed_items('sum'); - - return _aggregator_page_list($items, arg(1)); -} - -/** * Page callback: Displays all the items captured from the particular feed. * * @param \Drupal\aggregator\Plugin\Core\Entity\Feed $feed diff --git a/core/modules/aggregator/aggregator.routing.yml b/core/modules/aggregator/aggregator.routing.yml index 2b68646..a285eec 100644 --- a/core/modules/aggregator/aggregator.routing.yml +++ b/core/modules/aggregator/aggregator.routing.yml @@ -46,3 +46,10 @@ aggregator_opml_add: _form: '\Drupal\aggregator\Form\OpmlFeedAdd' requirements: _permission: 'administer news feeds' + +aggregator_page_last: + pattern: '/aggregator' + defaults: + _controller: '\Drupal\aggregator\Routing\AggregatorController::pageLast' + 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 dfed7fd..abef5af 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php @@ -7,14 +7,16 @@ namespace Drupal\aggregator\Routing; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Drupal\aggregator\FeedInterface; +use Drupal\Core\Config\ConfigFactory; use Drupal\Core\ControllerInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManager; -use Drupal\aggregator\FeedInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; /** * Returns responses for aggregator module routes. @@ -36,16 +38,36 @@ class AggregatorController implements ControllerInterface { protected $database; /** + * The config factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** * Constructs a \Drupal\aggregator\Routing\AggregatorController object. * * @param \Drupal\Core\Entity\EntityManager $entity_manager * The Entity manager. * @param \Drupal\Core\Database\Connection $database * The database connection. + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The config factory. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. */ - public function __construct(EntityManager $entity_manager, Connection $database) { + public function __construct(EntityManager $entity_manager, Connection $database, ConfigFactory $config_factory, ModuleHandlerInterface $module_handler) { $this->entityManager = $entity_manager; $this->database = $database; + $this->configFactory = $config_factory; + $this->moduleHandler = $module_handler; } /** @@ -54,7 +76,9 @@ public function __construct(EntityManager $entity_manager, Connection $database) public static function create(ContainerInterface $container) { return new static( $container->get('plugin.manager.entity'), - $container->get('database') + $container->get('database'), + $container->get('config.factory'), + $container->get('module_handler') ); } @@ -185,4 +209,22 @@ public function adminOverview() { return $build; } + /** + * Displays the most recent items gathered from any feed. + * + * @return string + * The rendered list of items for the feed. + */ + public function pageLast() { + drupal_add_feed('aggregator/rss', $this->configFactory->get('system.site')->get('name') . ' ' . t('aggregator')); + + // @todo Refactor this function once after all controller conversions are + // done. + $this->moduleHandler->loadInclude('aggregator', 'inc', 'aggregator.pages'); + $items = aggregator_load_feed_items('sum'); + + // @todo Refactor this function once after all controller conversions are + // done. + return _aggregator_page_list($items, arg(1)); + } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php index b60dde4..598f348 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php @@ -91,6 +91,11 @@ public function testFeedPage() { $feed = $this->createFeed(); $this->updateFeedItems($feed, 30); + // Check for presence of an aggregator pager. + $this->drupalGet('aggregator'); + $elements = $this->xpath("//ul[@class=:class]", array(':class' => 'pager')); + $this->assertTrue(!empty($elements), 'Individual source page contains a pager.'); + // Check for the presence of a pager. $this->drupalGet('aggregator/sources/' . $feed->id()); $elements = $this->xpath("//ul[@class=:class]", array(':class' => 'pager'));