Everyone knows that on some discussions comments can indent ludicriously. How can I limit it a depth of 2 replies only?

CommentFileSizeAuthor
#12 comment.module.diff5.73 KBpianomansam

Comments

ainigma32’s picture

Status: Active » Postponed (maintainer needs more info)

Do you want to make it impossible to add a comment after 2 replies or do you mean something else?

- Arie

Flying Drupalist’s picture

I want to make it impossible to add a comment after a depth of 2.

Comment
-comment
--comment
---comment NO WORK, auto defaults to->
--comment
Comment

ainigma32’s picture

Hmmm still not sure. So do you want to make it impossible for users to add a comment once the there are two comments or do you want to reset the indentation after two comments?

- Arie

Flying Drupalist’s picture

I don't want to do either, I want to make it so users can't do a level 3 indentation. When they use a reply that would normally result in a level 3 indentation, it ends up being a reply to the parent (and hence level 2).

Thanks for all your help.

ainigma32’s picture

Well it's not really what you want but this module http://drupal.org/project/flatcomments does prevent indenting getting crazy (by eliminating all indentation).

Will that do?

- Arie

Flying Drupalist’s picture

Thanks, I would like to still be able to use threading though.

ainigma32’s picture

Well looking at this one more time I still think the easiest solution would be to use the flatcomments module.
I looked at the code and the only thing this module does is making all replies into replies to the node.

If you mean by threading that you want to keep the parent-child relation of the comments, wouldn't your explanation in #4 mess up the thread too?

You might consider hacking the flatcomments module to only force the reply to be to the node when it is a reply to a node that's already indented twice. but I don't if that can be accomplished easily.

- Arie

Flying Drupalist’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Well it's enough for me to know that there's no already existing solution for it. I think some people are already working on modules for this.

Kane’s picture

Here what i've found:

In comment module you can find function comment_render in which you can find if else statements:

if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
          if ($comment->depth > $divs) {
            $divs++;
            $comments .= '<div class="indented">';
          }
          else {
            while ($comment->depth < $divs) {
              $divs--;
              $comments .= '</div>';
            }
          }
        }

If we alter conditions like this:

if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
          if ($comment->depth > $divs && $comment->depth <= $max_thread_depth) {
            $divs++;
            $comments .= '<div class="indented">';
          }
          else {
            while ($comment->depth < $divs) {
              $divs--;
              $comments .= '</div>';
            }
          }
        }

where $max_thread_depth stores number which represents how deep thread could be. Now we can put $max_thread_depth somewhere in theme global settings or in settings of comment in current content type (where you chose flat, threaded order of comments etc). There will be small field which will store it's value in database and will use it for comments in chosen content type. If value = 0 then thread depth's unlimited.
When $max_thread_depth is reached comments will be rendered flat.

I'm not a programmer so i hope those who know more than i can implement this stuff in comments.

If you don't mind hacking core module you can make something like that:

if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
          if ($comment->depth > $divs && $comment->depth <= 5) {
            $divs++;
            $comments .= '<div class="indented">';
          }
          else {
            while ($comment->depth < $divs) {
              $divs--;
              $comments .= '</div>';
            }
          }
        }

This code will limit depth of thread up to 5 replies in a row, then comments will be flat rendered.

By the way, maybe there's a way to rewrite this function in template.php?

toemaz’s picture

Or use css to flat the comments:

.indented .indented .indented .indented .indented .indented {
  margin-left:0;
}

where the number of .indented is where you wish to flat the indentation.

meecect’s picture

#10 confirmed. Thats a great solution.

pianomansam’s picture

Version: 6.5 » 6.24
Status: Closed (fixed) » Closed (won't fix)
StatusFileSize
new5.73 KB

Yes, I know, this is an old issue. But it's still incomplete. Solutions given in #9 and #10 seem to fix the issue on the surface. But as they description page on http://drupal.org/project/flatcomments mentions, a comment on a previous, non-top level comment will appear "underneath" it's parent issue, causing the comments to appear out of order.

There are two solutions to this dilemma. The first is to go the way of flatcomments.module and modify the way sub-comments are stored. This is a fine solution which wouldn't take much more than a custom hook_link_alter(). However, if you ever wanth to switch to a different display method, you can't because you are stuck.

The other solution would be to not modify the stored values, but instead to modify the display. This is quite difficult because the way comments are stored in the database. Comments only have parent comment ids stored, and a combined hierarchy column. In other words, to limit the amount of reply depth, this would have to be done on the PHP level, not SQL.

I've attached a patch with my attempt to do this. It appears to work in my environment but there is no guarantee it will work outside of it.

I'm also marking this as "won't fix) because Drupal 6.x is two versions behind.

zuernbernhard’s picture

Issue summary: View changes

Hm why not just hide the "Reply" link on the deepest possible (desired) level (comment depth) ?

liam morland’s picture

Version: 6.24 » 6.x-dev
Related issues: +#2786587: [PP-1] Add thread depth configuration to comments

Drupal core issue about limiting comment depth.