I used the approach provided here to reverse comments order in Drupal 8:
/** Implements hook_query_TAG_alter().
*
* Alter comments query to order by DESC as well as the default ASC.
*/
function MYMODULENAME_query_comment_filter_alter(QueryAlterableInterface $query) {
$orderby = &$query->getOrderBy();
// Sorting for threaded comments.
if (isset($orderby['torder'])) {
// Sort by root parent first, then normal threaded.
$query->addExpression("SUBSTRING_INDEX(c.thread, '.', 1)", 'rparent');
$orderby = array('rparent' => 'DESC') + $orderby;
}
// Sorting for flat comments.
else if (isset($orderby['c.cid'])) {
$direction = 'DESC';
$orderby['c.cid'] = $direction;
$orderby = array('c.created' => $direction) + $orderby;
}
}
but I receive the followig error when run the module:
Recoverable fatal error: Argument 1 passed to mymd_query_comment_filter_alter() must be an instance of QueryAlterableInterface, instance of Drupal\Core\Database\Query\PagerSelectExtender given, called in D:\wamp95\www\drupal83\core\lib\Drupal\Core\Extension\ModuleHandler.php on line 501 and defined in mymd_query_comment_filter_alter()
what is the problem and how should I solve it?