Sort comments and replies by their weight or hierarchical order or simply by their creation date, with a little subtlety.

This modules allows you to sort comments by their creation date, ascendant or descendant but it also allows you to sort replies in reverse order.

Why?

Reversing the order of the comment replies might be useful, see the following example.
Let's say the these following comments has been added from the top to the bottom, so, their creation date is ascending.

- comment 1
-- comment 1.1
-- comment 1.2
--- comment 1.2.1
--- comment 1.2.2
--- comment 1.2.3
- comment 2
-- comment 2.1
-- comment 2.2

If you sort from the newest to the oldest (DESC), you'll get the following result. This is what most of the modules related to sorting comments are doing, including those in the Related modules section.

- comment 2
-- comment 2.2
-- comment 2.1
- comment 1
-- comment 1.2
--- comment 1.2.3
--- comment 1.2.2
--- comment 1.2.1
-- comment 1.1

If you choose to reverse the order of the replies, and this is very particular to this module, you'll get:

- comment 2
-- comment 2.1
-- comment 2.2
- comment 1
-- comment 1.1
-- comment 1.2
--- comment 1.2.1
--- comment 1.2.2
--- comment 1.2.3

How does this works?

When you edit a node type and configure the options of the module, it fills up a new table provided by the module with the order of each comment. This order is computed from the array of comment of each node.
This array is a tree of comments flattened, the order or weight of each comment is taken from there and this is how the database get filled up.

Once it's done, I'm using a hook_query_tag_alter() to add an orderBy to the current query and get my comment sorted properly.

Related modules

This module was inspired by Comment sort Created by Patrick Drotleff.

Project information

Releases