This recipe explains how to load the result of a VBO view into Rules.
We will create a view that lists all nodes that are:
Created by user 1 (admin)
Promoted to the front page
More than two weeks old
We will then demote these nodes from the front page using Rules.
Go to Structure | Views and create a new view that lists all the nodes that are created by user 1, are promoted to front page, and are more than two weeks old, and add a VBO field to it. Call this new view Old admin content.
Go to Configuration | Workflow | Rules | Components and add a new Action set component. No parameters are needed; we will get the objects from the view.
Add a new Action, Views Bulk Operations | Load a list of entity objects from a VBO View and select the view we created in the first step, as shown in the following screenshot:
Optionally, enter a descriptive label for the variables and save the Action.
Add a new loop in the Actions section and select the VBO view result as the list data, shown as follows:
Optionally, enter a descriptive label for the variable to be used in the loop.
Add a new Action within the loop Node | Remove content from front page, as shown in the following screenshot:
Select the current node to be removed from the front page.
VBO views can be used to create a list of objects for Rules to execute an action on. This is a useful feature for developers and site builders who make extensive use of views on their sites. The advantage of using this feature is that we can create complex views with relationships and contextual filters (Rules provides an interface to pass arguments to views) and perform actions on the results.
In this example, we will create a new view that lists nodes that are created by user 1 (admin), are promoted to the front page, and are posted two weeks ago or earlier. Then, by adding a VBO field to the view, we make the results of the view available for Rules to use. Because the data type provided to Rules is a list, we can create a loop in our action and perform operations on each individual item.