Configuration API in Drupal

In this course, you will learn how to utilize Drupal's Configuration API to store, retrieve, and use configuration data in a module.

You'll learn how to make use of various aspects of Drupal's Configuration API, including:

  • Default configuration
  • Simple configuration
  • Configuration entities
  • Administrative settings forms
  • Configuration entity data in a form

Related course

To learn how to manage configuration and workflows in Drupal, see the course, Configuration Management in Drupal.

Tutorials in this course
More information

Drupal stores the settings that define how a site behaves as configuration data. Everything from the site name to image styles, roles, and view definitions are stored as configuration. The Configuration API gives modules, themes, and installation profiles a consistent way to store, retrieve, update, and provide this configuration in a structured and portable way.

In this tutorial, we'll:

  • Provide a high-level overview of the features of Drupal's Configuration API
  • Link to related tutorials where you can learn more and get hands-on practice working with configuration data in code.
Categories
Drupal 8, 9, 10, and 11
More information

In this tutorial, you'll learn about the two types of configuration data: simple configuration and configuration entities. By the end of this tutorial, you should have a better understanding of which type of configuration to use in your module.

Categories
Drupal 8, 9, 10, and 11
More information

When you create a module for Drupal, it can be useful to provide default configuration. This can be settings for a form, the placement of a block, or something more complex like the default image styles provided by the Image module in core. A module can provide default configuration for simple configuration or configuration entities.

In this tutorial, we will cover:

  • Possible locations for default configuration
  • What happens with configuration when a module is installed or uninstalled
  • Managing dependencies in configuration
  • Where to find examples of default configuration
More information

As we learned in Configuration Data Types, simple configuration is suitable for storing module settings as boolean values, integers, or text strings in one or more key/value pairs. In this tutorial, we'll walk through creating a schema and providing default configuration to store initial settings that a module needs to function.

Categories
Drupal 8, 9, 10, and 11
More information

When you are developing a module in Drupal, you can make certain functionality user-configurable. You can see this on Extend (admin/modules) in Drupal's administrative UI by looking for the Configure link near the module's description. To accomplish this, your module needs to define default settings in config/install/transcode_profile.settings.yml, create a settings form that will read those settings as the values for corresponding form fields, and update the settings when the form is submitted with updated values.

In this tutorial, we'll create a settings form that will be used as the module's Configure link in the Extend UI, as well as a menu link in an appropriate place in the administrative area. We'll use Drush, a command-line utility for Drupal, to speed up the process. We'll also create a default settings YAML file so that the settings form has something to read and update.

By the end of this tutorial, you should be able to get a configuration form up and running inside a custom module that will read and update a configuration object's values.

Categories
Drupal 8, 9, 10, and 11
More information

Now that we have some default simple configuration stored in a settings YAML file, let's utilize it in a form that our site administrators can use to update those values. We'll make use of some services and methods in Drupal's Configuration API in order to retrieve, update, and save simple configuration values with a form.

Categories
Drupal 8, 9, 10, and 11
More information

In this tutorial, we’re going to walk through the process of creating a custom configuration entity type in Drupal in a custom module. We'll be using Drush's generate entity:configuration command to create and update the files in our example module. After Drush has generated and updated the files for our configuration entity, we'll walk through each file and see how they define data structure, metadata, an administrative interface, and menu links for a configuration entity in Drupal.

By the end of this tutorial, you should be able to:

  • Use Drush to generate a configuration entity type
  • Identify files associated with a configuration entity and summarize the purpose and function of the code inside each file
More information

In this tutorial, you'll learn how to add a property to a configuration entity type in Drupal. Previously, we created a configuration entity type called video_preset and, using Drush, scaffolded the files and code to define a custom configuration entity type. Now, we'll add a new property called codec to this configuration entity type and update the code we created in the previous tutorial.

To add this new property to our custom configuration entity type, we need to update our schema file, configuration entity forms, the entity list builder class, and add getter and setter methods to our ConfigEntityType class.

More information

While we've already created configuration entity forms for creating, editing, and deleting configuration entities, in this tutorial, you'll learn how to use configuration entity data in the context of a module's settings (configuration) form. We'll refactor the module settings form we created previously and replace the textfield form element with a dropdown select list of our custom video preset configuration entities we created in another tutorial.

By the end of this tutorial, you should be able to:

  • Load configuration entities using an injected entity_type.manager service
  • Update the module settings form to use a select list of configuration entities
  • Save the settings form with the refactored field
This course appears in the following guides:
Module Development
Use Entity, Field, and Configuration APIs to structure and work with data in modules.

Work with Data in Modules