diff --git c/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php w/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php index e76bb04..56b5970 100644 --- c/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php +++ w/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php @@ -8,16 +8,19 @@ namespace Drupal\aggregator\Controller; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\aggregator\CategoryStorageControllerInterface; use Drupal\aggregator\FeedInterface; use Drupal\aggregator\ItemInterface; use Drupal\Core\Database\Connection; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; /** * Returns responses for aggregator module routes. */ -class AggregatorController extends ControllerBase { +class AggregatorController extends ControllerBase implements ContainerInjectionInterface { /** * The database connection. @@ -34,6 +37,29 @@ class AggregatorController extends ControllerBase { protected $categoryStorage; /** + * Constructs a \Drupal\aggregator\Controller\AggregatorController object. + * + * @param \Drupal\Core\Database\Connection $connection + * The database connection. + * @param \Drupal\aggregator\CategoryStorageControllerInterface $category_storage + * The category storage service. + */ + public function __construct(Connection $connection, CategoryStorageControllerInterface $category_storage) { + $this->connection = $connection; + $this->categoryStorage = $category_storage; + } + + /** + * {inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('database'), + $container->get('aggregator.category.storage') + ); + } + + /** * Presents the aggregator feed creation form. * * @return array @@ -63,8 +89,7 @@ public function viewFeed(FeedInterface $aggregator_feed) { $feed_source = $entity_manager->getRenderController('aggregator_feed') ->view($aggregator_feed, 'default'); // Load aggregator feed item for the particular feed id. - $items = $entity_manager->getStorageController('aggregator_item') - ->loadByFeed($aggregator_feed->id()); + $items = $entity_manager->getStorageController('aggregator_item')->loadByFeed($aggregator_feed->id()); // Print the feed items. $build = $this->buildPageList($items, $feed_source); $build['#title'] = $aggregator_feed->label(); @@ -81,7 +106,7 @@ public function viewFeed(FeedInterface $aggregator_feed) { * The render array with list of items for the feed. */ public function viewCategory($cid) { - $category = $this->getCategoryStorage()->load($cid); + $category = $this->categoryStorage->load($cid); $items = $this->entityManager()->getStorageController('aggregator_item')->loadByCategory($cid); $build = $this->buildPageList($items); $build['#title'] = $category->title; @@ -149,8 +174,7 @@ public function feedRefresh(FeedInterface $aggregator_feed, Request $request) { * A render array as expected by drupal_render(). */ public function adminOverview() { - $connection = $this->getConnection(); - $result = $connection->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'); + $result = $this->connection->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'), $this->t('Items'), $this->t('Last update'), $this->t('Next update'), $this->t('Operations')); $rows = array(); @@ -194,7 +218,7 @@ public function adminOverview() { '#empty' => $this->t('No feeds available. Add feed.', array('@link' => $this->urlGenerator()->generateFromPath('admin/config/services/aggregator/add/feed'))), ); - $result = $connection->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'); + $result = $this->connection->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'); $header = array(t('Title'), $this->t('Items'), $this->t('Operations')); $rows = array(); @@ -237,9 +261,8 @@ public function adminOverview() { * A render array. */ public function categories() { - $connection = $this->getConnection(); $entity_manager = $this->entityManager(); - $result = $connection->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'); + $result = $this->connection->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', @@ -301,10 +324,10 @@ public function sources() { $aggregator_summary_items = $this->config('aggregator.settings') ->get('source.list_max'); if ($aggregator_summary_items) { - $items = $entity_manager->getStorageController('aggregator_item')->loadByFeed($feed->id()); + $items = $entity_manager->getStorageController('aggregator_item') + ->loadByFeed($feed->id()); if ($items) { - $summary_items = $entity_manager - ->getRenderController('aggregator_item') + $summary_items = $entity_manager->getRenderController('aggregator_item') ->viewMultiple($items, 'summary'); } } @@ -323,29 +346,4 @@ public function sources() { return $build; } - /** - * Gets database connection service. - * - * @return \Drupal\Core\Database\Connection - **/ - protected function getConnection() - { - if (!empty($this->connection)) { - $this->connection = $this->container->get('database'); - } - } - - /** - * Gets category storage service. - * - * @return \Drupal\aggregator\CategoryStorageControllerInterface - **/ - protected function getCategoryStorage() - { - if (!empty($this->categoryStorage)) { - $this->categoryStorage = $this->container->get('aggregator.category.storage'); - } - return $this->categoryStorage; - } - }