diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index f7a908a..4dac822 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -162,10 +162,7 @@ function aggregator_menu() { $items['aggregator/categories/%aggregator_category'] = array( 'title callback' => '_aggregator_category_title', 'title arguments' => array(2), - 'page callback' => 'aggregator_page_category', - 'page arguments' => array(2), - 'access arguments' => array('access news feeds'), - 'file' => 'aggregator.pages.inc', + 'route_name' => 'aggregator_category', ); $items['aggregator/categories/%aggregator_category/view'] = array( 'title' => 'View', @@ -242,13 +239,14 @@ function aggregator_menu() { /** * Title callback: Returns a title for aggregator category pages. * - * @param $category - * An aggregator category. + * @param int $cid + * An aggregator category id. * - * @return + * @return string * A string with the aggregator category title. */ -function _aggregator_category_title($category) { +function _aggregator_category_title($cid) { + $category = db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $cid))->fetchObject(); return $category->title; } diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index c524505..44436f1 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -65,7 +65,7 @@ function aggregator_page_category($category) { // database by aggregator_category_load(). $items = aggregator_load_feed_items('category', $category); - return _aggregator_page_list($items, arg(3)); + return _aggregator_page_list($items, $category->cid); } /** diff --git a/core/modules/aggregator/aggregator.routing.yml b/core/modules/aggregator/aggregator.routing.yml index 2c69045..735e087 100644 --- a/core/modules/aggregator/aggregator.routing.yml +++ b/core/modules/aggregator/aggregator.routing.yml @@ -67,3 +67,10 @@ aggregator_categories: _content: '\Drupal\aggregator\Controller\AggregatorController::categories' requirements: _access_aggregator_categories: 'TRUE' + +aggregator_category: + pattern: '/aggregator/categories/{cid}' + defaults: + _controller: '\Drupal\aggregator\Controller\AggregatorController::category' + requirements: + _permission: 'access news feeds' diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php index 3fd7dae..d35ed7d 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php @@ -323,4 +323,27 @@ public function sources() { return $build; } + /** + * Displays feed items aggregated in a category. + * + * @param int $cid + * The category id for which to list all of the aggregated items. + * + * @return string + * The rendered list of items for the feed. + */ + public function category($cid) { + $category = $this->database->query('SELECT cid, title FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $cid))->fetchObject(); + drupal_add_feed('aggregator/rss/' . $category->cid, $this->configFactory->get('system.site')->get('name') . ' ' . t('aggregator - @title', array('@title' => $category->title))); + + // @todo move included functions to controller. + module_load_include('inc', 'aggregator', 'aggregator.pages'); + + // It is safe to include the cid in the query because it's loaded from the + // database by aggregator_category_load(). + $items = aggregator_load_feed_items('category', $category); + + return _aggregator_page_list($items, $cid); + } + }