In this video we’ll create a Rule that automatically unpublishes a node when it is flagged as offensive five times. This will help eliminate offensive content from your site until you can edit it or delete it yourself.
Add the Rule
- Go to “Configuration => Workflow => Rules” (admin/config/workflow/rules)
- Click "Add new rule"
- Name: Unpublish Offensive Content
- React on event: A node has been flagged, under “Flag as offensive”
- (Save)
Add condition to check if the node has been flagged 5 times
- Click “Add condition”
- Select Condition: Node has flagging count
- Flag: Flag as offensive
- Node: flagged-node
- Number: 5
- (Save)
- Select Condition: Node has flagging count
Add action to unpublish the content
- Click “Add action”
- Unpublish content
- Content: flagged-node
- (Save)
- Unpublish content
- (Save changes)
To test this, I’ll create additional users and flag the content as offensive.
...
Now that the content has been flagged four times, I’ll flag it one more time.
Once I do, when I refresh, we’ll see that it is no longer visible on the home page. It’s also not visible in the “Offensive Content” view. Let’s edit the view to display unpublished content as well as published.
- Edit the View
- In the “Filter Criteria” section, remove “Content: Published”
- (Save)
Now when we head back to the “Offensive Content” view, we see the article has been flagged 5 times, and that it is unpublished. Perfect!
In the last video I mentioned that we didn’t want to select “Administrator” as the role for that Rule. Instead we said that when a user with the “Content Moderator” role edits a node, remove the flags. This rule states that after five flags the node should be unpublished. If the role in the first Rule were set to “Administrator”, then when the node is automatically unpublished after five flags by this Rule, all flags would also be removed because the unpublish action is performed as if it were done by an administrator. I specified a new role for Content Moderators so that we could use both of these rules.
Now let’s take a look at how we can use the Flag module to create a list of our favorite content, display each user’s favorite content on their profile, and create a dynamic list of the most favorited content.