Create an Admin Page using Views in Drupal

Don’t forget to subscribe to our YouTube channel to stay up-to-date.

The Views module is great for creating pages in Drupal and is beneficial when creating custom admin pages.

In this tutorial, you’ll learn how to create a custom views page that will allow you to manage article content types.

The view will be accessible via a tab from the admin content area, and it’ll have the following functionality:

  • Display all articles in a table format
  • Edit or delete articles
  • Run bulk operations on articles
  • Search articles using keywords in the title

Here is what the page will look like:

Working admin page built by views.

What is Views in Drupal?

Views in Drupal is a module that empowers administrators to create, manage, and display customized lists of content. It offers a user-friendly interface to define filters, sorting criteria, and display formats, enabling dynamic and personalized content presentations without coding.

Step 1: Create Admin Page

Go to Structure, Views, click on “Add view”, and fill in the new view settings using the table below:

Views settingValue
View nameArticle Admin
ShowContent of type Article sorted by newest first
Create a pageChecked
Pathadmin/content/articles
Display formatTable of fields

It’s important to set the path to /admin/content/articles as this is required to set the menu tab correctly. The path can be changed later on.

Step 2: Add Fields to Views Page

Let’s add a few extra fields to the view: changed date (last updated), author, published and operation links. We already have the title field as views added it for us.

Click on Add in the Fields section.

Search for Changed, select it and click on Add and Configure fields.

Adjust the date settings and label if required, then click on Apply.

Click on Add again in the Fields section, search for Authored by, and click Add and Configure fields.

Adjust the field as required, then click on Apply.

Click Add and search for Published and add it to the view.

From Output format select Custom and enter Published into Custom output for TRUE and Unpublished for Custom output for FALSE. Then click Apply.

Click on Add in the Fields section one final time, and add Operations links to the view.

Change the Label so it’s just Operations and click on Apply.

Scrolling down to the Preview section you should see the following fields:

  1. Title
  2. Changed
  3. Authored by
  4. Published
  5. Operations:

If you want to add more fields to your view, do that now.

Step 3: Display Fields as a Table

You want to ensure your fields are displayed in a table format.

Go to the Format section, above Fields, and next to Format, ensure Table is selected.

If something else such as Unformatted list is the format, click on the link and select Table from the pop-up window. Then click on Apply.

Scroll down to the bottom and make sure you save the view.

Step 4: Add Menu Tab

At this point, we do have a working page. If you save the view and go to /admin/content/articles you should see a table with article content. Make sure, of course, you have actual articles on your site.

Let’s add a menu tab so this page is accessible from the main Content page.

Edit the view and click on No Menu next to Menu in the Page settings section.

Select Menu tab from Type and add Article into Menu link title.

Scroll down select <Administration> from Parent, and add 100 to Weight. Then click on Apply and save the view.

If you return to the page, you should see an Article tab; /admin/content/articles.

Most importantly, if you click on any other tabs, Articles will be visible and accessible.

Note: If the tab doesn’t appear, check the following. Ensure the path starts with /admin/content/ANYTHING and set the Parent to <Administration>.

Step 5: Add Page Permission

If you open a private browser and go to /admin/content/articles, you’ll notice the page is accessible.

Usually these types of pages should only be visible to editors.

Let’s lock down the page so it’s only visible to users with “Access the Content overview page” permission.

Edit the view and click on View published content in the Page settings section.

Select Access the Content overview page from the Permission dropdown and click Apply.

NOTE: Every Drupal site has different requirements for roles and permissions, so select the appropriate permission for your project.

Save the view and go to /admin/content/articles in the private browser and you should get an access denied.

Step 5: Configure Filters and add Exposed Filter

We need to adjust the filters on the view to show published and unpublished content and add an exposed filter. This will allow editors to search articles by their title.

Go to the Filters section on the edit view screen, click Published, and remove the filter. This will allow us to view all articles, published or unpublished.

Click Add in the Filter criteria section and add the Title filter to the view.

Check Expose this filter to visitors… and select Contains from Operator, then click on Apply.

Scroll down to the preview section and see Title as an exposed filter and unpublished content.

Step 6: Add Empty Text and Result Summary

In the previous step we added an exposed filter that let’s you search article by title.

However, when you search for a keyword that doesn’t exist you just get a blank page.

Let’s add a message if no results are returned and add a results summary displaying the article amount in the view.

Click Add in the view edit screen’s No results behavior section.

Search for Text area and add it to the view.

Add a message into the Content text area. Add something such as “No articles were found.”.

Scroll down to the preview section and search using a keyword that doesn’t exist. You should see the “no result” message that you added above.

Click on Add in the Header section on the view edit screen.

Search for Result summary and add it to the view.

Leave the default tokens in Display; “Displaying @start – @end of @total” and click on Apply.

Scroll down to the preview section and see an article count in the Header section. You can add the same Result summary to the footer if you like.

Step 7: Add Bulk Operations to View

This page will be used to manage articles let’s add the ability to bulk publish and delete articles.

Click on Add in the Fields section on the views edit page.

Search for Node operations bulk form and add it to the view.

Select Only selected actions from Available actions and check Delete content, Publish content and Unpublish content from Selected actions.

Click on the down arrow next to Add and Rearrange.

Move the node operation field to the top of the list.

Save and go to the view and you should see an Action dropdown and checkboxes on the left. Simply select article by using the checkboxes and run an action by choosing one from the dropdown.

Summary

In this tutorial, you learnt how to create a custom page and make it accessible in Drupal’s backend area. We added a table display, title search, bulk operations and more.

Frequently Asked Questions

What are Drupal Views?

Views is a powerful module that allows you to create and manage custom lists of content on your Drupal website. Views can be used to display content in various ways, including lists, tables, and charts.

What is the purpose of views in Drupal?

The Views module creates a list of content in Drupal. The list could be pages, articles or any custom content.

2 thoughts on “Create an Admin Page using Views in Drupal”

  1. This is a great tutorial. I’m currently trying to a build an Admin page that houses numerous View blocks so writers for a news site can see some stats. I think this is a good launching point to achieve that. Thanks Ivan!

    1. Hi Ryan,

      Create the blocks using Views, then to place them out use Layout Builder.

      Install the “Layout Builder” module and enable it on a content type. Then you can create sections and add blocks (the block views you created) to them.

      Cheers,
      Ivan

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top