diff --git a/core/modules/history/history.services.yml b/core/modules/history/history.services.yml index a466b56..64fcc21 100644 --- a/core/modules/history/history.services.yml +++ b/core/modules/history/history.services.yml @@ -1,4 +1,4 @@ services: history.repository: class: Drupal\history\HistoryRepository - arguments: ['@database'] + arguments: ['@database', '@current_user'] diff --git a/core/modules/history/lib/Drupal/history/HistoryRepository.php b/core/modules/history/lib/Drupal/history/HistoryRepository.php index d0ae942..0bbabb1 100644 --- a/core/modules/history/lib/Drupal/history/HistoryRepository.php +++ b/core/modules/history/lib/Drupal/history/HistoryRepository.php @@ -31,13 +31,23 @@ class HistoryRepository implements HistoryRepositoryInterface { protected $connection; /** + * The current user. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $currentUser; + + /** * Constructs the history repository service. * * @param \Drupal\Core\Database\Connection $connection * The database connection. + * @param \Drupal\Core\Session\AccountInterface $current_user + * The current user. */ - public function __construct(Connection $connection) { + public function __construct(Connection $connection, AccountInterface $current_user) { $this->connection = $connection; + $this->currentUser = $current_user; } /** @@ -62,7 +72,7 @@ public function getLastViewed($entity_type, $entity_ids) { $result = $this->connection->select('history', 'h') ->fields('h', array('entity_id', 'timestamp')) - ->condition('uid', \Drupal::currentUser()->id()) + ->condition('uid', $this->currentUser->id()) ->condition('entity_type', $entity_type) ->condition('entity_id', array_keys($entities_to_read), 'IN') ->execute();