diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index a835bfa..8730bf7 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1122,7 +1122,7 @@ function comment_load($cid, $reset = FALSE) { * Use \Drupal\comment\CommentManager::getCountNewComments(). */ function comment_num_new($entity_id, $entity_type, $field_name = NULL, $timestamp = 0) { - $entity = entity_load($entity_type, $entity_id); + $entity = \Drupal::entityManager()->getStorage($entity_type)->load($entity_id); return \Drupal::service('comment.manager')->getCountNewComments($entity, $field_name, $timestamp); } diff --git a/core/modules/comment/comment.services.yml b/core/modules/comment/comment.services.yml index 38cdd91..ff9d756 100644 --- a/core/modules/comment/comment.services.yml +++ b/core/modules/comment/comment.services.yml @@ -7,7 +7,7 @@ services: comment.manager: class: Drupal\comment\CommentManager - arguments: ['@entity.manager', '@entity.query', '@config.factory', '@string_translation', '@url_generator', '@module_handler'] + arguments: ['@entity.manager', '@entity.query', '@config.factory', '@string_translation', '@url_generator', '@module_handler', '@current_user'] comment.statistics: class: Drupal\comment\CommentStatistics diff --git a/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php index c8f1b19..6ec96d3 100644 --- a/core/modules/comment/src/CommentManager.php +++ b/core/modules/comment/src/CommentManager.php @@ -15,6 +15,7 @@ use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; @@ -67,6 +68,13 @@ class CommentManager implements CommentManagerInterface { protected $moduleHandler; /** + * The current user. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $currentUser; + + /** * Construct the CommentManager object. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -81,14 +89,17 @@ class CommentManager implements CommentManagerInterface { * The url generator service. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler service. + * @param \Drupal\Core\Session\AccountInterface $current_user + * The current user. */ - public function __construct(EntityManagerInterface $entity_manager, QueryFactory $query_factory, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, UrlGeneratorInterface $url_generator, ModuleHandlerInterface $module_handler) { + public function __construct(EntityManagerInterface $entity_manager, QueryFactory $query_factory, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, UrlGeneratorInterface $url_generator, ModuleHandlerInterface $module_handler, AccountInterface $current_user) { $this->entityManager = $entity_manager; $this->queryFactory = $query_factory; $this->userConfig = $config_factory->get('user.settings'); $this->stringTranslation = $string_translation; $this->urlGenerator = $url_generator; $this->moduleHandler = $module_handler; + $this->currentUser = $current_user; } /** @@ -303,7 +314,7 @@ public function forbiddenMessage(EntityInterface $entity, $field_name) { public function getCountNewComments(EntityInterface $entity, $field_name = NULL, $timestamp = 0) { // @todo Replace module handler with optional history service injection // after http://drupal.org/node/2081585 - if (\Drupal::currentUser()->isAuthenticated() && $this->moduleHandler->moduleExists('history')) { + if ($this->currentUser->isAuthenticated() && $this->moduleHandler->moduleExists('history')) { // Retrieve the timestamp at which the current user last viewed this entity. if (!$timestamp) { if ($entity->getEntityTypeId() == 'node') {