Settings Forms in Drupal

Modules frequently need to create forms to collect module specific configuration, since this is a common task Drupal provides a set of helper classes and APIs to make this process easier.

This course covers the basics of defining a settings form, retrieving and setting configuration values, and saving configuration data. You will also learn how to add configuration settings to themes and provide administrators with more control over the theme's behavior.

Key topics

  • Creating a settings form in a module
  • Retrieving and setting configuration values in a form
  • Loading and saving configuration entity data
  • Customizing the theme settings form in code
  • Using the Configuration API to manage module settings
  • Providing default configuration values and managing configuration synchronization
  • Practical examples of settings forms and configuration management
Tutorials in this course
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.

Drupal 8, 9, 10, and 11
More information

In Drupal's Appearance UI, all themes get a theme settings form. As a theme developer, you can customize the theme settings form, enabling site administrators to have more control over the appearance of the theme.

In this tutorial, we'll show you how to add admin-configurable settings to your theme. In the process of doing this, we'll use a variety of theme and module development skills and assume you have some familiarity with using Drupal's Form API, Configuration API, and theme system (see Prerequisites).

By the end of this tutorial, you will be able to provide custom theme settings that an administrator can use to modify the appearance of the theme.

This course appears in the following guides:
Module Development
Learn to use Drupal's Form API to define, validate, and process forms in modules and themes.

Develop Forms in Drupal