diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php index a7d47e8..0ad1889 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php @@ -23,6 +23,43 @@ class AggregatorCategoryBlock extends BlockBase { /** + * The database connection. + * + * @var \Drupal\Core\Database\Connection + */ + protected $connection; + + /** + * Constructs an AggregatorFeedBlock object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param array $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Database\Connection $connection + * The database connection. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, Connection $connection) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->connection = $connection; + } + + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('database') + ); + } + + /** * Overrides \Drupal\block\BlockBase::settings(). */ public function settings() { @@ -45,7 +82,7 @@ public function access() { * Overrides \Drupal\block\BlockBase::blockForm(). */ public function blockForm($form, &$form_state) { - $result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title'); + $result = $this->connection->query('SELECT cid, title FROM {aggregator_category} ORDER BY title'); $options = array(); foreach ($result as $category) { $options[$category->cid] = check_plain($category->title); @@ -79,8 +116,8 @@ public function blockSubmit($form, &$form_state) { */ public function build() { $cid = $this->configuration['cid']; - if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $cid))->fetchObject()) { - $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $this->configuration['block_count'], array(':cid' => $category->cid)); + if ($category = aggregator_category_load($cid)) { + $result = $this->connection->queryRange('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $this->configuration['block_count'], array(':cid' => $category->cid)); $more_link = array( '#theme' => 'more_link', '#url' => 'aggregator/categories/' . $category->cid, diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php index 8d258fa..022d2f0 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php @@ -8,8 +8,13 @@ namespace Drupal\aggregator\Plugin\Block; use Drupal\block\BlockBase; +use Drupal\block\BlockInterface; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Database\Connection; +use Drupal\Core\Entity\EntityStorageControllerInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides an 'Aggregator feed' block with the latest items from the feed. @@ -20,7 +25,56 @@ * module = "aggregator" * ) */ -class AggregatorFeedBlock extends BlockBase { +class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInterface { + + /** + * The entity storage controller for feeds. + * + * @var \Drupal\Core\Entity\EntityStorageControllerInterface + */ + protected $storageController; + + /** + * The database connection. + * + * @var \Drupal\Core\Database\Connection + */ + protected $connection; + + /** + * Constructs an AggregatorFeedBlock object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param array $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Entity\EntityStorageControllerInterface $storage_controller + * The entity storage controller for feeds. + * @param \Drupal\Core\Database\Connection $connection + * The database connection. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageControllerInterface $storage_controller, Connection $connection) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->storageController = $storage_controller; + $this->connection = $connection; + } + + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('plugin.manager.entity')->getStorageController('aggregator_feed'), + $container->get('database') + ); + } + /** * Overrides \Drupal\block\BlockBase::settings(). @@ -45,7 +99,7 @@ public function access() { * Overrides \Drupal\block\BlockBase::blockForm(). */ public function blockForm($form, &$form_state) { - $feeds = entity_load_multiple('aggregator_feed'); + $feeds = $this->storageController->loadMultiple(); $options = array(); foreach ($feeds as $feed) { $options[$feed->id()] = $feed->label(); @@ -77,9 +131,9 @@ public function blockSubmit($form, &$form_state) { * {@inheritdoc} */ public function build() { - // Plugin IDs look something like this: aggregator_feed_block:1. - if ($feed = aggregator_feed_load($this->configuration['feed'])) { - $result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", 0, $this->configuration['block_count'], array(':fid' => $feed->id())); + // Load the selected feed. + if ($feed = $this->storageController->load($this->configuration['feed'])) { + $result = $this->connection->queryRange("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", 0, $this->configuration['block_count'], array(':fid' => $feed->id())); $more_link = array( '#theme' => 'more_link', '#url' => 'aggregator/sources/' . $feed->id(),