diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorFeedBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorFeedBlock.php index 663bf5f..286cd20 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorFeedBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorFeedBlock.php @@ -7,14 +7,17 @@ namespace Drupal\aggregator\Plugin\Derivative; -use Drupal\Component\Plugin\Derivative\DerivativeInterface; +use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface; +use Drupal\Core\Database\Connection; +use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides block plugin definitions for aggregator feeds. * * @see \Drupal\aggregator\Plugin\block\block\AggregatorFeedBlock */ -class AggregatorFeedBlock implements DerivativeInterface { +class AggregatorFeedBlock implements ContainerDerivativeInterface { /** * List of derivative definitions. @@ -24,16 +27,55 @@ class AggregatorFeedBlock implements DerivativeInterface { protected $derivatives = array(); /** + * The database connection. + * + * @var \Drupal\Core\Database\Connection + */ + protected $connection; + + /** + * The translation manager + * + * @var \Symfony\Component\Translation\TranslatorInterface + */ + protected $translationManager; + + /** + * Constructs a AggregatorFeedBlock object. + * + * @param string $base_plugin_id + * The base plugin ID. + * @param \Drupal\Core\Database\Connection $connection + * The database connection. + */ + public function __construct($base_plugin_id, Connection $connection, TranslatorInterface $translation_manager) { + $this->basePluginId = $base_plugin_id; + $this->connection = $connection; + $this->translationManager = $translation_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, $base_plugin_id) { + return new static( + $base_plugin_id, + $container->get('database'), + $container->get('string_translation') + ); + } + + /** * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinition(). */ public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) { if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) { return $this->derivatives[$derivative_id]; } - $result = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $derivative_id))->fetchObject(); + $result = $this->connection->query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $derivative_id))->fetchObject(); $this->derivatives[$derivative_id] = $base_plugin_definition; $this->derivatives[$derivative_id]['delta'] = $result->fid; - $this->derivatives[$derivative_id]['admin_label'] = t('@title feed latest items', array('@title' => $result->title)); + $this->derivatives[$derivative_id]['admin_label'] = $this->translationManager->translate('@title feed latest items', array('@title' => $result->title)); return $this->derivatives[$derivative_id]; } @@ -42,11 +84,11 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin */ public function getDerivativeDefinitions(array $base_plugin_definition) { // Add a block plugin definition for each feed. - $result = db_query('SELECT fid, title FROM {aggregator_feed} WHERE block <> 0 ORDER BY fid'); + $result = $this->connection->query('SELECT fid, title FROM {aggregator_feed} WHERE block <> 0 ORDER BY fid'); foreach ($result as $feed) { $this->derivatives[$feed->fid] = $base_plugin_definition; $this->derivatives[$feed->fid]['delta'] = $feed->fid; - $this->derivatives[$feed->fid]['admin_label'] = t('@title feed latest items', array('@title' => $feed->title)); + $this->derivatives[$feed->fid]['admin_label'] = $this->translationManager->translate('@title feed latest items', array('@title' => $feed->title)); } return $this->derivatives; }