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..d8a2ac1 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. @@ -31,21 +33,41 @@ class AggregatorController implements ControllerInterface { /** * The database connection. * - * @var \Drupal\Core\Database\Connection; + * @var \Drupal\Core\Database\Connection */ 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') ); } @@ -90,8 +114,8 @@ public function feedAdd() { */ public function feedRefresh(FeedInterface $aggregator_feed, Request $request) { // @todo CSRF tokens are validated in page callbacks rather than access - // callbacks, because access callbacks are also invoked during menu link - // generation. Add token support to routing: http://drupal.org/node/755584. + // callbacks, because access callbacks are also invoked during menu link + // generation. Add token support to routing: http://drupal.org/node/755584. $token = $request->query->get('token'); if (!isset($token) || !drupal_valid_token($token, 'aggregator/update/' . $aggregator_feed->id())) { throw new AccessDeniedHttpException(); @@ -111,7 +135,13 @@ public function feedRefresh(FeedInterface $aggregator_feed, Request $request) { public function adminOverview() { $result = $this->database->query('SELECT f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block ORDER BY f.title'); - $header = array(t('Title'), t('Items'), t('Last update'), t('Next update'), t('Operations')); + $header = array( + t('Title'), + t('Items'), + t('Last update'), + t('Next update'), + t('Operations'), + ); $rows = array(); foreach ($result as $feed) { $row = array(); @@ -150,7 +180,7 @@ public function adminOverview() { '#theme' => 'table', '#header' => $header, '#rows' => $rows, - '#empty' => t('No feeds available. Add feed.', array('@link' => url('admin/config/services/aggregator/add/feed'))), + '#empty' => t('No feeds available. Add feed.', array('@link' => url('admin/config/services/aggregator/add/feed'))), ); $result = $this->database->query('SELECT c.cid, c.title, COUNT(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title'); @@ -179,10 +209,28 @@ public function adminOverview() { '#theme' => 'table', '#header' => $header, '#rows' => $rows, - '#empty' => t('No categories available. Add category.', array('@link' => url('admin/config/services/aggregator/add/category'))), + '#empty' => t('No categories available. Add category.', array('@link' => url('admin/config/services/aggregator/add/category'))), ); 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)); + } }