diff --git a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php index 299113c..aad6ae2 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php @@ -98,4 +98,11 @@ public function isUnique($title, $cid = NULL) { return (empty($rows)); } + /** + * {@inheritdoc} + */ + public function loadByItem($item_id) { + return $this->database->query('SELECT c.cid, c.title, ci.iid FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid AND ci.iid = :iid', array(':iid' => $item_id)); + } + } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php index a4ab4db..90fb48f 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php @@ -66,5 +66,16 @@ public function delete($cid); */ public function isUnique($title, $cid = NULL); + /** + * Loads aggregator categories for an aggregator item. + * + * @param int $item_id + * The aggregator item ID. + * + * @return array + * An array of objects containing item ID, category ID and title. + */ + public function loadByItem($item_id); + } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/AggregatorCategorizeFormBase.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/AggregatorCategorizeFormBase.php index 74f4347..e73f684 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/AggregatorCategorizeFormBase.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/AggregatorCategorizeFormBase.php @@ -7,6 +7,7 @@ namespace Drupal\aggregator\Form; +use Drupal\aggregator\CategoryStorageControllerInterface; use Drupal\aggregator\FeedInterface; use Drupal\aggregator\ItemStorageControllerInterface; use Drupal\Component\Utility\String; @@ -50,6 +51,13 @@ protected $aggregatorItemStorage; /** + * The aggregator category storage controller. + * + * @var \Drupal\aggregator\CategoryStorageControllerInterface + */ + protected $categoryStorage; + + /** * The feed to use. * * @var \Drupal\aggregator\FeedInterface @@ -68,11 +76,12 @@ * @param \Drupal\aggregator\ItemStorageControllerInterface $aggregator_item_storage * The aggregator item storage controller. */ - public function __construct(EntityRenderControllerInterface $aggregator_item_renderer, Connection $database, Config $config, ItemStorageControllerInterface $aggregator_item_storage) { + public function __construct(EntityRenderControllerInterface $aggregator_item_renderer, Connection $database, Config $config, ItemStorageControllerInterface $aggregator_item_storage, CategoryStorageControllerInterface $category_storage) { $this->aggregatorItemRenderer = $aggregator_item_renderer; $this->database = $database; $this->config = $config; $this->aggregatorItemStorage = $aggregator_item_storage; + $this->categoryStorage = $category_storage; } /** @@ -83,7 +92,8 @@ public static function create(ContainerInterface $container) { $container->get('plugin.manager.entity')->getRenderController('aggregator_item'), $container->get('database'), $container->get('config.factory')->get('aggregator.settings'), - $container->get('plugin.manager.entity')->getStorageController('aggregator_item') + $container->get('plugin.manager.entity')->getStorageController('aggregator_item'), + $container->get('aggregator.category.storage') ); } @@ -104,7 +114,7 @@ public function buildForm(array $form, array &$form_state, array $items = NULL) ); if ($items && ($form_items = $this->aggregatorItemRenderer->viewMultiple($items, 'default'))) { foreach (element_children($form_items) as $iid) { - $categories_result = $this->database->query('SELECT c.cid, c.title, ci.iid FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid AND ci.iid = :iid', array(':iid' => $iid)); + $categories_result = $this->categoryStorage->loadByItem($iid); $selected = array(); foreach ($categories_result as $category) {