Using Rules and Views Bulk Operations

In a previous article I described how to use the EVA and Entity Reference modules to create a simple reviews system for the Article content type.  To improve this system, it would be good if when an Article is deleted, that all the reviews that reference that Article are also deleted.

To do this we will use Rules, Conditional Rules, and Views Bulk Operations

Rules

The rules module allows site administrators to define conditionally executed actions based on occurring events (known as reactive or ECA rules). It's a replacement with more features for the trigger module in Drupal core.

Example use cases

  • Build flexible content publishing workflows changes
  • Send customized mails to notify your users about important events
  • Create custom redirections, system messages, breadcrumbs, ...
  • Altering variable or entity data depending on user role
  • Executing custom php code after comment added
  • Deleting entities that reference an entity that is being deleted

The Rules module reacts to Events and performs various actions when those events occur. Conditions can be applied to rules. Once an event triggers Rules, and the set conditions are met, Rules can perform various actions or loops of actions.

Rules Components

Rules components can be used to organize combinations of actions or conditions. For example, you may have many actions you wish to take after one type of event. You an event may invoke a rules action component which will contain several action rules which will fire when your event happens. This is handy because it allows you to organize and separate each action for simpler editing especially in the case of complicated conditions for executing an action.

http://drupal.org/project/rules

Conditional Rules

Conditional Rules allows much more flexibility in the conditioning of rules actions. Adds If/Else, switch, and while structures to be placed in the actions area of a Rule

http://drupal.org/project/rules_conditional

Views Bulk Operations

Views Bulk Operations creates an interface to perform actions on views query result entities. In Rules it adds an action to load a list of entity ids or objects which can be acted on by other rules actions.

http://drupal.org/project/views_bulk_operations

How-To Guide

Create VBO View to use in rule

  1. Create a new view showing content of type review, no page or other views displays.
  2. Add a field Bulk Operations: Content and at least one other field
  3. Settings for the Bulk Operation field, Under 'Selected Bulk Operations', Check the Delete item checkbox,
  4. Add contextual filter which is the entity reference field
  5. Pager settings: display all items

Create Rule

  1. Create new Rule React to event: After deleting content
  2. Add condition: ‘Content is of type’ and select Article
  3. Add action: Load a list of entity objects from VBO view
  4. Select New view that was created in steps 1‐4 and pass the node:nid (of deleted node) as the argument to the view
  5. Name the List Reviews List
  6. Add Loop, list to act on is Reviews List, can change name of current item is list (optional)
  7. Nested in loop add action Delete Entity, use [list‐item] or whatever you named the current list item

Tags: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.
By submitting this form, you accept the Mollom privacy policy.