/* Implements hook_query_TAG_alter().
https://www.drupal.org/node/1095656#comment-7885467
* * Alter comments query to order by DESC as well as the default ASC. */
function supporthk_query_comment_filter_alter(QueryAlterableInterface $query) {
$orderby = &$query->getOrderBy();
$expressions = &$query->getExpressions();
// Sorting for threaded comments.
if (isset($orderby['torder'])) {
// Get rid of the expressions that prepare the threads for ASC ordering.
// Simply order by the thread field.
unset($expressions['torder']);
unset($orderby['torder']);
$orderby['c.thread'] = 'DESC';
}else{ // Sorting for flat comments.
$direction = 'DESC';
if (isset($orderby['c.cid'])) {
unset($orderby['c.cid']);
}
$orderby['c.created'] = $direction;
$orderby['c.cid'] = $direction;
}
}