Unpublish node when other node with same title is created

Events happening in the community are now at Drupal community events on www.drupal.org.
elcapitan82's picture

I am building a site which depends on user-created content. In order to encourage users to contribute, I have a node type called Suggestion, which has a title field and nothing else. On my frontpage a list of these suggestions is displayed.

Now, When a user creates a Page with a title that matches one of the suggestions, I want that Suggestion to be automatically unpublished.

So the steps are:

WHEN...
Page is created

IF...
Title of created Page equals title of existing Suggestion

THEN...
Unpublish existing Suggestion

I figure that Rules is the right tool for the job, but I am not sure how to set up the conditions to make this happen.

Any help is greatly appreciated. Thanks!

Comments

VBO to the rescue!

itangalo's picture

What you want to do requires a query against existing Drupal data, which can be done using Views. By using Views Bulk Operations you can use Views to perform actions (such as rule sets) on the view results.

The approach would look like this:
1. Create a view that takes a node title as argument, and displays all Suggestions with that title.
2. Make the view into Bulk Operation style, and make the action 'Unpublish node' available in it. (You'll find the action in the list of available actions listed in the bulk operation settings.)
3. Add a triggered rule, activated on new Page creation. Have it call the VBO above. This can be somewhat tricky, but this blogpost I wrote some time ago explains it pretty well.

Good luck!
//Johan Falk, NodeOne, Sweden

PS: There has been so many questions where the answer is Rules + VBO that I should really write a more detailed description of how to use them together. Or perhaps record a screencast.

It works!

elcapitan82's picture

I finally got around to look at this and your approach worked like a charm. As I am not a programmer, I was a bit unsure of the syntax of the view argument needed, but your fine screencast took care of that.

Thanks for your help, Johan!

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: