I used flag module to deal with abused forum posts and comments. In some cases, I can unpublish/delete them which have been flagged as an abuse conetnt dierctly, such as spams. In other cases, may there be posts with strong emotions or improper contents, provoke everybody in the forum. We hope to keep those posts/comments in the forum but give them some special display styles to notify members who visit them.

I need to find a way to add specific CSS class to those post/comment which have been flagged by administrators, so that I can write some CSS rules to make them displaying differently.

Not sure how to do it with this module and flag module. Any suggestion?


troky’s picture

Priority: Critical » Normal

This is not critical priority.

tky’s picture

I got these codes from my friend which can add different classes in forum posts and comments that have been flagged as abused.

// dpm($content);

if(isset($content['comments'])) {
  $entity_id = $content['body']['#object']->nid;
  $flag = flag_get_flag('abuse_node');

  if($flag && $flag->is_flagged($entity_id)) {
    $classes = $classes . ' topic-flag';

if(isset($content['comment_body'])) {
  $entity_id = $content['body']['#object']->cid;
  $flag = flag_get_flag('abuse_comment');

  if($flag && $flag->is_flagged($entity_id)) {
    $classes = $classes . ' comment-flag';

I added them in advanced-forum-post.tpl.php in my subtheme folder of zen, and successfully saw the forum posts which were flagged as abuse node got .topic-flag class. Comments got .comment-flag one as well.

So far so good. However, I noticed that this change only works for login user but not anonymous.
No matter what I did, clear cache or disable modules which related with cache issue, if the user logout, the flagged nodes and comments won't got thoses classes.

Wondering why this happened. Any suggestion?

tky’s picture

Status: Active » Closed (fixed)

I found the key point of above problem is that I set both flags as non-global flags, so that some permission issues prevent anonymous from getting correct output classes.
After I deleted these two flags and replaced them with another two global flags with exactly the same names, the problem was gone.

As a conclusion, the whole process of intergrate advanced forum with abuse flag in display would be following steps:

  1. Set two global flags for forum node type and comment respectively.
  2. Copy advanced-forum.naked.post.tpl.php in sites/all/modules/advanced_forum/styles/naked, paste it into sites/all/themes/your_theme and rename it as advanced-forum-post.tpl.php
  3. Put those code in #2 in the beggining of advanced-forum-post.tpl.php within and tag
  4. Check if there are additional classes after you flagged some forum posts and comment as abused.
  5. Wright CSS rules,such as .topic-flag{color: #ffffff;}, make flagged content hard to read or invisible.

That's it!