Change record status: 
Project: 
Introduced in branch: 
8.x
Introduced in version: 
8.0.0-alpha14
Description: 

Many procedural functions in comment.module have been removed. Their functionality was moved to methods inside
CommentManager or CommentStorage.

The removed functions with their new counterparts: (Please see the below examples for usage of arguments.)

  • comment_count_unpublished() -> CommentStorage::getUnapprovedCount(); see example for changes to return value.
  • comment_get_display_page() -> CommentStorage::getDisplayOrdinal()
  • comment_get_display_ordinal() -> CommentStorage::getDisplayOrdinal() leaving the last argument to the default value 1
  • comment_get_recent(): removed. To render a list of recent comments, check the 'comments_recent' view.
  • comment_get_thread() -> CommentStorage::loadThread(); now returns comment objects, not comment IDs.
  • comment_new_page_count() -> CommentStorage::getNewCommentPageNumber(); see example for changes to return value.
  • comment_num_new() -> CommentManager:: getCountNewComments($entity, $field_name, $timestamp);

comment_count_unpublished()

D7

// Returns a menu title which includes the number of unapproved comments.
$text = comment_count_unpublished();

D8

// Returns number of unapproved comments.
// Procedural code.
$number_comments = \Drupal::entityManager()->getStorage('comment')
  ->getUnapprovedCount()
// Objective code (assuming you have the entity manager, preferably injected into your class).
$number_comments = $entityManager->getStorage('comment')
  ->getUnapprovedCount()
$text = t('Unapproved comments (@count)', array('@count' => $number_comments))

comment_get_display_page() / comment_get_display_ordinal()

D7

// Get page number for a comment. Needs the type (bundle) of the node which comments are connected to.
$page_number = comment_get_display_page($cid, $node_type);
// Get display ordinal for a comment. Needs the type (bundle) of the node which comments are connected to.
$ordinal = comment_get_display_ordinal($cid, $node_type);

D8

// Replacement for comment_display_page():

// Include the constants for $comment_mode. Your choices will be
// CommentManagerInterface::COMMENT_MODE_FLAT and CommentManagerInterface::COMMENT_MODE_THREADED.
use Drupal\comment\CommentManagerInterface;
...
// Procedural code.
$page_number = \Drupal::entityManager()->getStorage('comment')
  ->getDisplayOrdinal($comment, $comment_mode, $comments_per_page);

// Objective code (assuming you have the entity manager, preferably injected into your class).
$page_number = $entityManager->getStorage('comment')
  ->getDisplayOrdinal($comment, $comment_mode, $comments_per_page);
// Replacement for comment_display_ordinal()
use Drupal\comment\CommentManagerInterface;
...
// Procedural code.
$ordinal = \Drupal::entityManager()->getStorage('comment')
  ->getDisplayOrdinal($comment, $default_mode);

// Objective code (assuming you have the entity manager, preferably injected into your class).
$ordinal = $entityManager->getStorage('comment')
  ->getDisplayOrdinal($comment, $default_mode);

comment_get_thread()

D7

// Get an ordered array of IDs of comments to display.
$cids = comment_get_thread($node, $comment_mode, $comments_per_page);

D8

// Get an ordered array of comment entities to display.
// Extra 2nd argument: the field name on the entity which holds the comments. When in doubt, use 'comment'.
// Extra 5th argument: the pager ID. When in doubt, leave blank.
// Procedural code.
$comments = \Drupal::entityManager()->getStorage('comment')
  ->loadThread($entity, $field_name, $comment_mode, $comments_per_page, $pager_id);

// Objective code (assuming you have the entity manager, preferably injected into your class).
$page_number = $entityManager->getStorage('comment')
  ->loadThread($entity, $field_name, $comment_mode, $comments_per_page, $pager_id);

comment_new_page_count()

D7

// Get page number for a comment. 
// $query_arg is either NULL or array('page' => $page_number) where $page_number > 0.
$query_arg = comment_get_display_page($total_comments, $new_comments, $node);

D8

// Extra argument: the field name on the entity which holds the comments. 
//   Leave empty to use the default field name 'comment'.
// Return argument changed: it's an integer. 
//   Where NULL would be returned it's now 0, otherwise it's the value that would be inside the array.
// Procedural code.
$page_number = \Drupal::entityManager()->getStorage('comment')
  ->getNewCommentPageNumber($total_comments, $new_comments, $entity, $field_name)
// If you need e.g. a query argument to feed to url() for e.g. implementing a pager, convert this yourself:
$query_arg = $page_number ? array('page' => $page_number) : NULL;
$url = url(SOME-URL, array('query' => $query_arg));

// Objective code (assuming you have the entity manager, preferably injected into your class).
$page_number = $entityManager->getStorage('comment')
  ->getNewCommentPageNumber($total_comments, $new_comments, $entity, $field_name);

comment_num_new()

D7

// Get the number of new comments since $timestamp (or whenever the node
// was last viewed). Return FALSE in anonymous user sessions.
$number_new_comments = comment_num_new($nid, $timestamp = 0);

D8

// Extra 2nd argument: the field name on the entity which holds the comments. 
//   Leave empty to use the default field name 'comment'.
// Procedural code.
$page_number = \Drupal::service('comment.manager')
  ->getCountNewComments($entity, $field_name, $timestamp);

// Objective code (assuming you have the CommentManager class, preferably injected into your class).
$page_number = $comment_manager
  ->getCountNewComments($entity, $field_name, $timestamp);
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done