Save Time, Maintain Consistency: Bulk-Update Drupal Content Instantly with the Field Defaults Module

May 16 2024

Authored by Nadiia Nykolaichuk and Bryan Sharpe.

Smart approaches and tools are shaping the future of content management and website administration, leaving behind the days of tedious manual work. With a click of a button, you can instantly make consistent changes to multiple pages, almost as if wielding a magical wand.

One of the instant-action “magical wands” for modern-day Drupal websites is the Field Defaults module, which we are proud to say has been created by Bryan Sharpe of our team. It’s one of the numerous modules Bryan contributed to the Drupal community, alongside modules to extend CKEditor 5, Drupal Views, and more. 

The Field Defaults module helps teams save time, increase efficiency, eliminate human error, and add consistency to their websites by bulk-updating content field values. In this article, we’ll explore the details of the module’s work, discuss use cases for which it might be helpful, and carefully walk you through every step of using it.

The key features of the Field Defaults module

Field Defaults is a lightweight yet powerful Drupal module enabling you to set default field values and optionally batch-update all existing content with them (or bulk-update, whatever term you prefer). This works both for adding news fields and editing existing ones. The module requires minimal configuration and is friendly to content editors and site administrators thanks to its intuitively understandable interface.

Beyond content: support for any fieldable entity type. The word “content” is used here in the general sense while the module works with all Drupal entity types that have fields. This means that in addition to “standard” content such as articles, news, events, or testimonials, it can bulk-update field values in user accounts, media types, taxonomy terms, custom block types, and more. 

A wide range of options with Drupal fields. Fields in Drupal can actually cover any content element. So you can bulk-update your content with a default text, title, number, link, email address, category, user, price, and so on — the sky’s the limit. We recently explored how fields work as a robust solution to shape your content structure, and how the interface for creating fields has been revamped in Drupal 10.2 to make content modeling more user-friendly. Of course, we will see the new Field UI in this article as well.

The option to update or not update existing content. As you set the field default values, the Field Defaults module gives you the choice to bulk-update previously added content or leave it as is. In the second case, it will start applying the new default values to upcoming content only. With this, the module demonstrates flexibility to suit various website needs and ensures data safety. 

The option to change or not change the original update date. The bulk update date might not be meaningful so you might want to avoid displaying it in your content. Luckily, the module provides the option to retain the original date and time when the content items were last changed.

Multilingual support. The Field Defaults module supports bulk-updating field values in translations, which makes it great for multilingual websites built with Drupal.

Potential use cases and scenarios for the Field Defaults module

Detailed example #1. Let’s assume your blog never had any “author” field, but now you’d like to add one and set the default author to “Editorial team” (or “Admin,” or the name of your main blog writer). However, when you’ve added the field, tons of existing blog posts on your Drupal website have an empty value for it — in other words, they still have no author.

Should you manually go through all the blog posts to add the author? No way! Just set the field value to “Editorial team” via the Field Defaults module. Then simply click one button and all your blog posts are automatically populated with “Editorial team” as the author. If you need to overwrite the author in specific blog posts to be someone else, you’ll always be able to do it manually.

All newly created content will have the “Editorial team” author as well unless you choose to manually specify someone else when adding a content item.

More examples:

  • The email address of the department or person held responsible has changed and needs to be updated in the email field attached to study programs, volunteer opportunities, job listings, conferences, or property listings.
  • Your higher-ed website has published a series of upcoming lectures and you suddenly need to update their location to your new auditorium instead of the old one.
  • You decided to categorize your Drupal blog or add the default category to all your existing blog posts.
  • You’d like to auto-populate all your previously added and upcoming articles with some default tags.
  • Your standard webinar or workshop has a “duration” field and it needs to be changed on a regular basis (for example, from 1 hour to 1 hour 20 minutes).
  • You have built a new “Admission Requirements” page and you’d now like for all of your study programs to display a link to it.
  • You’d like to add an announcement message like “Don’t forget to bring your laptop” as an additional text area to all your series of workshops. 
  • You need to specify the name of the new instructor for the classes you offer.

The Field Defaults module appears to be a perfect match for use cases when the default field value is relevant to all items of a certain content type. For example, your event location has changed on a regular basis and is valid for all upcoming events. Another example is when most of your articles are authored by your main writer and only specific ones, if any, are written by others.

In some cases, the more granularity you have in your Drupal content types, the better the module might meet your needs. For example, you offer yoga classes, swimming lessons, and spin classes. There are different instructors for each of these types of activity, and then suddenly the instructor has changed for one of them. If you have a separate content type for each type of class, and the same “Instructor” field is not re-used across them, it would be perfectly safe to change the default instructor for just one of them via the Field Defaults module. 

How to use the Field Defaults module: step-by-step guide

1. Safety measures

Bulk-updating fields is a responsible task. You want to be on the safe side and prevent unwanted changes. So it’s highly recommended to back up your database or perform bulk updates first in a development environment to confirm the results before applying changes to your live Drupal website. This ensures you can roll back if something goes wrong.

2. Installation and global settings

Install the Field Defaults module per normal. When it’s installed, go to Configuration > System > Field default settings. You’ll see the “Retain original entity updated time” checkbox:

  • If the checkbox is selected, the original date and time of the last update to your content will be retained.
  • If the checkbox is unselected, it’s the bulk-update date and time that will be displayed as your content’s last update date and time.
The Field Defaults module’s settings to retain or not the original content update date and time.
The Field Defaults module’s settings to retain or not the original content update date and time.

3. Usage in fields

Let’s imagine you have a “Mindful yoga class” content type with several content items of this type and you’d like to add an “Instructor” field. The new instructor for mindful yoga classes will be no other than Master Yoda. This special user has been added in advance in the “People” section.

An example of a user to be displayed for the “Instructor” field.
An example of a user to be displayed for the “Instructor” field.

3.1. Adding a new field to your content structure (optional step)

Since the module works with both new and existing fields, the step of adding a field can be skipped if you already have the field you need. In this example, let’s create a new “Instructor” field from scratch. Go to Structure > Content types > Mindful yoga class > Manage fields and click the “Create a new field” button. You’ll need to select the “Reference” field type, which is exactly what it’s called in the new Field UI. 

Adding an “Instructor” field, step 1: choosing “Reference” as the field type.
Adding an “Instructor” field, step 1: choosing “Reference” as the field type.

At the bottom of the page, choose what type of entity you’re referencing, which in this case should be “User.”  

Adding an “Instructor” field, step 2: choosing “User” as the entity type for reference.
Adding an “Instructor” field, step 2: choosing “User” as the entity type for reference.

Next, click the “Continue” button and finish the field setup on the 2nd page. The default settings are absolutely fine, but you might want to make the field required, allow multiple instructors to be listed, and so on. 

As usual with adding a field, check the “Manage form display” and “Manage display” tabs of the content type to make sure it is displayed as desired on the back end and front end, respectively. Among other things, you can hide or display the field label and reorder the fields to meet your needs. 

Checking the “Manage display” tab to make sure the field is displayed as needed.
Checking the “Manage display” tab to make sure the field is displayed as needed.

3.2. Setting the default values and bulk-updating your content

If you skipped the step of new field creation, you can join in right from here. Go to Structure > Content types > Mindful yoga class > Manage fields and click to edit the “Instructor” field. 

At the bottom of the field settings, you’ll see the “Set default value” checkbox. Once you check it, a subtab opens where you can specify the desired default value for the field (in this case, “Master Yoda”).

The next subtab allows you to check one of the boxes:

  • overwrite existing content with the selected default value(s), with the website language(s) also specified
  • keep existing values
The Field Defaults module’s settings to specify default values and bulk-update content.
The Field Defaults module’s settings to specify default values and bulk-update content.

 Of course, for this example, let’s overwrite the values, which will show the key strength of the module. Click “Save settings” and you’ll immediately see the bulk-updating process in action. It finishes with a status message about how many entities have been updated with the default values. In this example, there were 5 content items but imagine them being 100 or 1000, which is a normal case for content-rich Drupal websites.

A status message about the number of entities successfully bulk-updated.
A status message about the number of entities successfully bulk-updated.

Just to check the results, let’s go to one of the content items of the “Mindful yoga class” content type and yes, there’s the “Instructor” field that has been successfully defaulted to “Master Yoda.”

An example of a content item with the ”Instructor” field successfully defaulted to the needed value.
An example of a content item with the ”Instructor” field successfully defaulted to the needed value.

Seeing content updated automatically is a great moment to take a deep breath and relax as if you really were doing the yoga class. No fuss, no rush — the Field Defaults module has taken care of all the work for you. May efficiency be with you!

Final thoughts

Regardless of which field defaults you might need to set, we wish for you to have one strong and unchanging default — always using the “work smarter, not harder” approach on your Drupal website. The Field Defaults module is its brilliant embodiment. We are happy to support the development of this and other smart tools that automate, streamline, and simplify your team’s workflows. Let us know if you need our assistance with their seamless setup.

Learn from us
Sign up and receive our monthly insights directly in your inbox!

Subcribe to newsletter (no spam)

Fields