This recipe describes how to add a specific taxonomy term to a list of nodes using Views Bulk Operations (VBO) and Rules.
Install and enable Views, Views UI, and Views Bulk Operations. Go to Structure | Views and create a new table view that lists all nodes posted on the site, and add a Bulk operations: Content field to it.
Create a new rule component, select the Rule plugin and require an Entity | Node parameter. Name the new component
Add taxonomy term to node
.Add a Condition, Entities | Entity has field, use node as the entity, and set the field to field_tags.
Add a new Action, Data | Add an item to a list and set the value to node:field-tags.
In the Item to add fieldset, click on the Switch to the direct input mode button and enter the ID of the taxonomy term to add, as shown in the following screenshot:
Go back to the view and click on the Bulk Operations: Content field.
In the popup window, select the rule component we created in the SELECTED OPERATIONS fieldset, as shown in the following screenshot:
Views Bulk Operations can use Rules components to execute Actions on a list of entities and objects. We can create the Rules components with parameters and VBO will make these components available as operations in our Bulk Operations field configuration, if the field type matches the component's parameter type. For example, when creating a component that requires a Node
parameter, we need to add the same type of VBO field (Content: Bulk Operations) to the view, because this is how VBO determines what kind of parameter is being passed to Rules.
If we want this feature to be a bit more flexible and choose a taxonomy term, we want to add to the nodes instead of always adding a preconfigured term ID, we can do the following:
Add a new Entity | Taxonomy term parameter to our component, set the machine name to the term.
Edit our Action, Add an item to a list, in the Item to add fieldset, click on Switch to data selection, and enter term. This is given in the following screenshot:
Now when executing the operation, VBO will display a configuration screen where we can enter the ID of the taxonomy term we want to add to the node.