diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module
index d2c07af..f7a908a 100644
--- a/core/modules/aggregator/aggregator.module
+++ b/core/modules/aggregator/aggregator.module
@@ -143,9 +143,7 @@ function aggregator_menu() {
);
$items['aggregator/categories'] = array(
'title' => 'Categories',
- 'page callback' => 'aggregator_page_categories',
- 'access callback' => '_aggregator_has_categories',
- 'file' => 'aggregator.pages.inc',
+ 'route_name' => 'aggregator_categories',
);
$items['aggregator/rss'] = array(
'title' => 'RSS feed',
@@ -255,17 +253,6 @@ function _aggregator_category_title($category) {
}
/**
- * Access callback: Determines whether there are any aggregator categories.
- *
- * @return
- * TRUE if there is at least one category and the user has access to them;
- * FALSE otherwise.
- */
-function _aggregator_has_categories() {
- return user_access('access news feeds') && (bool) db_query_range('SELECT 1 FROM {aggregator_category}', 0, 1)->fetchField();
-}
-
-/**
* Implements hook_permission().
*/
function aggregator_permission() {
diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc
index b6d4062..c524505 100644
--- a/core/modules/aggregator/aggregator.pages.inc
+++ b/core/modules/aggregator/aggregator.pages.inc
@@ -319,41 +319,6 @@ function template_preprocess_aggregator_item(&$variables) {
}
/**
- * Page callback: Displays all the categories used by the Aggregator module.
- *
- * @return string
- * An HTML formatted string.
- *
- * @see aggregator_menu()
- */
-function aggregator_page_categories() {
- $result = db_query('SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY c.cid, c.title, c.description');
-
- $build = array(
- '#type' => 'container',
- '#attributes' => array('class' => array('aggregator-wrapper')),
- '#sorted' => TRUE,
- );
- $aggregator_summary_items = config('aggregator.settings')->get('source.list_max');
- foreach ($result as $category) {
- $summary_items = array();
- if ($aggregator_summary_items) {
- if ($items = aggregator_load_feed_items('category', $category, $aggregator_summary_items)) {
- $summary_items = entity_view_multiple($items, 'summary');
- }
- }
- $category->url = url('aggregator/categories/' . $category->cid);
- $build[$category->cid] = array(
- '#theme' => 'aggregator_summary_items',
- '#summary_items' => $summary_items,
- '#source' => $category,
- );
- }
-
- return $build;
-}
-
-/**
* Page callback: Generates an RSS 0.92 feed of aggregator items or categories.
*
* @return string
diff --git a/core/modules/aggregator/aggregator.routing.yml b/core/modules/aggregator/aggregator.routing.yml
index e25527c..2c69045 100644
--- a/core/modules/aggregator/aggregator.routing.yml
+++ b/core/modules/aggregator/aggregator.routing.yml
@@ -60,3 +60,10 @@ aggregator_sources:
_content: '\Drupal\aggregator\Controller\AggregatorController::sources'
requirements:
_permission: 'access news feeds'
+
+aggregator_categories:
+ pattern: '/aggregator/categories'
+ defaults:
+ _content: '\Drupal\aggregator\Controller\AggregatorController::categories'
+ requirements:
+ _access_aggregator_categories: 'TRUE'
diff --git a/core/modules/aggregator/aggregator.services.yml b/core/modules/aggregator/aggregator.services.yml
index 639ed2d..cf74241 100644
--- a/core/modules/aggregator/aggregator.services.yml
+++ b/core/modules/aggregator/aggregator.services.yml
@@ -8,3 +8,8 @@ services:
plugin.manager.aggregator.processor:
class: Drupal\aggregator\Plugin\AggregatorPluginManager
arguments: [processor, '@container.namespaces']
+ access_check.aggregator.categories:
+ class: Drupal\aggregator\Access\CategoriesAccessCheck
+ arguments: ['@database']
+ tags:
+ - { name: access_check }
diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php
index eac277c..3fd7dae 100644
--- a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php
+++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php
@@ -13,6 +13,7 @@
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Routing\PathBasedGeneratorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -52,6 +53,13 @@ class AggregatorController implements ControllerInterface {
protected $moduleHandler;
/**
+ * The url generator.
+ *
+ * @var \Drupal\Core\Routing\PathBasedGeneratorInterface
+ */
+ protected $urlGenerator;
+
+ /**
* Constructs a \Drupal\aggregator\Controller\AggregatorController object.
*
* @param \Drupal\Core\Entity\EntityManager $entity_manager
@@ -65,11 +73,12 @@ class AggregatorController implements ControllerInterface {
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
- public function __construct(EntityManager $entity_manager, Connection $database, ConfigFactory $config_factory, ModuleHandlerInterface $module_handler) {
+ public function __construct(EntityManager $entity_manager, Connection $database, ConfigFactory $config_factory, ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator) {
$this->entityManager = $entity_manager;
$this->database = $database;
$this->configFactory = $config_factory;
$this->moduleHandler = $module_handler;
+ $this->urlGenerator = $url_generator;
}
/**
@@ -80,7 +89,8 @@ public static function create(ContainerInterface $container) {
$container->get('plugin.manager.entity'),
$container->get('database'),
$container->get('config.factory'),
- $container->get('module_handler')
+ $container->get('module_handler'),
+ $container->get('url_generator')
);
}
@@ -125,7 +135,7 @@ public function feedRefresh(FeedInterface $aggregator_feed, Request $request) {
// @todo after https://drupal.org/node/1972246 find a new place for it.
aggregator_refresh($aggregator_feed);
- return new RedirectResponse(url('admin/config/services/aggregator', array('absolute' => TRUE)));
+ return new RedirectResponse($this->urlGenerator->generateFromPath('admin/config/services/aggregator', array('absolute' => TRUE)));
}
/**
@@ -176,7 +186,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' => $this->urlGenerator->generateFromPath('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');
@@ -205,13 +215,48 @@ 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' => $this->urlGenerator->generateFromPath('admin/config/services/aggregator/add/category'))),
);
return $build;
}
/**
+ * Displays all the categories used by the Aggregator module.
+ *
+ * @return array
+ * A render array.
+ */
+ public function categories() {
+ // @todo Refactor this once all controller conversions are complete.
+ $this->moduleHandler->loadInclude('aggregator', 'inc', 'aggregator.pages');
+
+ $result = $this->database->query('SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY c.cid, c.title, c.description');
+
+ $build = array(
+ '#type' => 'container',
+ '#attributes' => array('class' => array('aggregator-wrapper')),
+ '#sorted' => TRUE,
+ );
+ $aggregator_summary_items = $this->configFactory->get('aggregator.settings')->get('source.list_max');
+ foreach ($result as $category) {
+ $summary_items = array();
+ if ($aggregator_summary_items) {
+ if ($items = aggregator_load_feed_items('category', $category, $aggregator_summary_items)) {
+ $summary_items = $this->entityManager->getRenderController('aggregator_item')->viewMultiple($items, 'summary');
+ }
+ }
+ $category->url = $this->urlGenerator->generateFromPath('aggregator/categories/' . $category->cid);
+ $build[$category->cid] = array(
+ '#theme' => 'aggregator_summary_items',
+ '#summary_items' => $summary_items,
+ '#source' => $category,
+ );
+ }
+ return $build;
+ }
+
+ /**
* Displays the most recent items gathered from any feed.
*
* @return string
@@ -263,7 +308,7 @@ public function sources() {
->viewMultiple($items, 'summary');
}
}
- $feed->url = url('aggregator/sources/' . $feed->id());
+ $feed->url = $this->urlGenerator->generateFromPath('aggregator/sources/' . $feed->id());
$build[$feed->id()] = array(
'#theme' => 'aggregator_summary_items',
'#summary_items' => $summary_items,