diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index b544908..dd844ab 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -176,10 +176,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', @@ -256,13 +253,15 @@ 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) { + // TODO category is not an entity so is not loaded automatically. + $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 6248012..da7b71c 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -73,6 +73,9 @@ function aggregator_page_source_form($form, $form_state, $feed) { * * @see aggregator_menu() * @ingroup forms + * + * TODO Duplicates AggregatorController::category() + * remove this when no longer used by aggregator_page_category_form(). */ function aggregator_page_category($category) { drupal_add_feed('aggregator/rss/' . $category->cid, config('system.site')->get('name') . ' ' . t('aggregator - @title', array('@title' => $category->title))); @@ -81,7 +84,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 bf02d5c..715fa7c 100644 --- a/core/modules/aggregator/aggregator.routing.yml +++ b/core/modules/aggregator/aggregator.routing.yml @@ -25,3 +25,10 @@ aggregator_feed_add: _controller: '\Drupal\aggregator\Routing\AggregatorController::feedAdd' requirements: _permission: 'administer news feeds' + +aggregator_category: + pattern: '/aggregator/categories/{cid}' + defaults: + _controller: '\Drupal\aggregator\Routing\AggregatorController::category' + 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 66f1fbd..315a4cc 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Routing/AggregatorController.php @@ -7,6 +7,8 @@ namespace Drupal\aggregator\Routing; +use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Database\Connection; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\ControllerInterface; use Drupal\Core\Entity\EntityManager; @@ -24,20 +26,44 @@ class AggregatorController implements ControllerInterface { protected $entityManager; /** + * The config factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** + * The database connection. + * + * @var \Drupal\Core\Database\Connection + */ + protected $database; + + /** * Constructs a \Drupal\aggregator\Routing\AggregatorController object. * * @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) { + public function __construct(EntityManager $entity_manager, ConfigFactory $config_factory, Connection $database) { $this->entityManager = $entity_manager; + $this->configFactory = $config_factory; + $this->database = $database; } /** * {inheritdoc} */ public static function create(ContainerInterface $container) { - return new static($container->get('plugin.manager.entity')); + return new static( + $container->get('plugin.manager.entity'), + $container->get('config.factory'), + $container->get('database') + ); } /** @@ -56,4 +82,29 @@ public function feedAdd() { return entity_get_form($feed); } + /** + * Form constructor to list 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); + } + }