Don’t forget to subscribe to our YouTube channel to stay up-to-date.
Views Bulk Operations, commonly referred to as VBO, is a module that allows specifically defined actions that can be simultaneously executed on rows of Views data.
This tutorial will show how to install this module and set up a simple View with a defined action and VBO field. We will then demonstrate how to use VBO to perform this action on selected View rows. We will also show how you can define permissions for roles to use our defined action.
Drupal Views Series
1. Getting Started with Views in Drupal
2. Create Infinite Scroll pages using Views Infinite Scroll in Drupal
3. Hide Block if no Results are Returned using Views in Drupal
4. Bulk Update Content using Views Bulk Operations in Drupal
5. Add Custom Tab to User Profile Page with Views in Drupal
6. Conditionally Display View Fields using Views Conditional in Drupal
We can easily download VBO using Composer:
composer require drupal/views_bulk_operations
To enable VBO you can use drush:
drush en views_bulk_operations -y
After enabling any Drupal module, it’s always a good idea to clear the cache:
Create a View
For this tutorial, we will create a simple View that will list recently created content of type “Basic Page”.
For our View to display results, we should have some content of “Basic Page” already created. If you don’t already have content, go ahead and create some content of type “Basic Page”.
Now let’s set up a very simple View. Our View just lists nodes of type “Basic Page” in a table format. Here is a screenshot of the Views configuration screen:
And here is the output of the above View:
Add VBO field to the View
The magic happens when we add the VBO field to our View. For this tutorial, we will create an “Unpublish” action that will allow users to unpublish nodes of “Basic Page” in our View.
1. In the Fields section of our View, add the “Views bulk operation” field:
2. After clicking on “Add and configure fields”, look for the “Selected Actions” section. We are going to select “Unpublish content item” and give it a label of “Unpublish” and then click on “Apply”. (You can select multiple actions as needed.) This is shown below:
Now your View should look like this:
3. If you had selected multiple actions, they would all be shown in the “Action” dropdown list. You can select some rows using the VBO field and apply the Action of “Unpublish” to see the changes. Follow the 3 steps in this screenshot:
The following screenshot shows the results after doing this to the first 2 rows. Notice the “Published” column values have been updated.
Specify which roles can apply specific Actions (Optional)
What if you only wanted to allow specific roles to use specific actions? The awesome developers of Views Bulk Operations included a sub module called “Actions Permissions” to accomplish just that!
Let’s say we only wanted the “Authenticated User” role to use the “Unpublish” action in our above View.
After enabling the sub module “Actions Permissions”, go to Admin >> People >> Permissions and in the list of Actions Permissions you should select “Execute the Unpublish content item action on Content” as shown below:
Now only the “Authenticated User” role can apply the “Unpublish” action in our View. This “Actions Permissions” sub module becomes a very powerful feature when you have multiple roles in your site.
Views Bulk Operations (VBO) allows users to perform actions on View rows data. In this tutorial, we have shown how you can add the VBO field to a View and optionally give a specific role permissions to use this action.