diff --git b/core/modules/comment/comment.module a/core/modules/comment/comment.module index 796f09f..73bc3db 100644 --- b/core/modules/comment/comment.module +++ a/core/modules/comment/comment.module @@ -1243,7 +1243,7 @@ function comment_load($cid, $reset = FALSE) { * to node). * * @return int|FALSE - * The number of new comments or FALSE if the user is not logged in. + * The number of new comments or FALSE if the user is not authenticated. */ function comment_num_new($entity_id, $entity_type, $field_name = NULL, $timestamp = 0) { return \Drupal::service('comment.manager')->getCountNewComments($entity_type, $entity_id, $field_name, $timestamp); diff --git b/core/modules/comment/lib/Drupal/comment/CommentManager.php a/core/modules/comment/lib/Drupal/comment/CommentManager.php index f6cd26f..136bb5c 100644 --- b/core/modules/comment/lib/Drupal/comment/CommentManager.php +++ a/core/modules/comment/lib/Drupal/comment/CommentManager.php @@ -8,11 +8,11 @@ namespace Drupal\comment; use Drupal\Component\Utility\String; -use Drupal\field\FieldInfo; +use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Database\Connection; use Drupal\Core\Session\AccountInterface; +use Drupal\field\FieldInfo; /** * Comment manager contains common functions to manage comment fields. @@ -54,6 +54,10 @@ class CommentManager implements CommentManagerInterface { * The field info service. * @param \Drupal\Core\Entity\EntityManager $entity_manager * The entity manager service. + * @param \Drupal\Core\Database\Connection $connection + * The database connection. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. */ public function __construct(FieldInfo $field_info, EntityManager $entity_manager, Connection $connection, ModuleHandlerInterface $module_handler) { $this->fieldInfo = $field_info; @@ -219,28 +223,29 @@ public function getFieldUIPageTitle($field_name) { } /** - * Returns the number of new comments for an user and the specified entity. + * Returns the number of new comments available on a given entity for a user. * * @param string $entity_type * Entity type of the entity to which the comments are attached. * @param int $entity_id * Entity ID of the entity to which the comments are attached. * @param string $field_name - * (optional) The field_name to count comments for. Defaults to NULL. + * The field_name to count comments for. Defaults to any field. * @param int $timestamp - * Time to count from (defaults to time of last user access to node). + * Time to count from. Defaults to time of last user access to node. * @param \Drupal\Core\Session\AccountInterface $account - * The user for which to count the new comments. Defaults to NULL. + * The user for which to count the new comments. Defaults to the current + * user. * * @return int|FALSE - * The number of new comments or FALSE if the user is not logged in. + * The number of new comments or FALSE if the user is not authenticated. */ public function getCountNewComments($entity_type, $entity_id, $field_name = NULL, $timestamp = 0, AccountInterface $account = NULL) { if (!isset($account)) { $account = \Drupal::currentUser(); } if ($account->isAuthenticated() && $this->moduleHandler->moduleExists('history')) { - // Retrieve the timestamp when the current user last viewed this entity. + // Retrieve the timestamp when the user last viewed this entity. if (!$timestamp) { if ($entity_type == 'node') { $timestamp = history_read($entity_id); @@ -257,7 +262,7 @@ public function getCountNewComments($entity_type, $entity_id, $field_name = NULL } } } - $timestamp = ($timestamp > HISTORY_READ_LIMIT ? $timestamp : HISTORY_READ_LIMIT); + $timestamp = $timestamp > HISTORY_READ_LIMIT ? $timestamp : HISTORY_READ_LIMIT; // Use the timestamp to retrieve the number of new comments. $query = $this->connection->select('comment', 'c'); @@ -274,9 +279,7 @@ public function getCountNewComments($entity_type, $entity_id, $field_name = NULL return $query->execute() ->fetchField(); } - else { - return FALSE; - } + return FALSE; } }