Site Config is a Drupal module that provides a flexible way to manage global site configurations using a plugin-based system. It allows developers to define custom configuration sets that can be easily edited via a unified settings form and exposed through REST or JSON:API.
- Plugin-based architecture: Define configuration sets as plugins.
- Unified Settings Form: All configurations are manageable from a single administrative interface.
- Multilingual Support: Supports translatable configurations.
- Flexible Storage: Choose between Drupal's State API or Configuration API for storage.
- Entity Integration: Built-in support for entity autocompletes.
- API Ready: Submodules for REST and JSON:API integration.
- Drupal 9, 10, or 11.
jsonapi_resourcesmodule (only if usingsite_config_jsonapi).multivalue_form_elementmodule (optional, for multi-value field support).
- Install the module as you would any other Drupal module.
- Enable the main
site_configmodule. - (Optional) Enable
site_config_restorsite_config_jsonapiif you need to expose your configurations via API.
The main settings form is located at /admin/site-config. Here you will find
all the configuration elements defined by the active Site Config plugins.
To create a new configuration set, you need to define a plugin in your custom module.
Create a file in src/Plugin/SiteConfig/YourPluginName.php:
<?php
namespace Drupal\your_module\Plugin\SiteConfig;
use Drupal\site_config\SiteConfigPluginBase;
/**
* Provides a site config plugin.
*
* @SiteConfig(
* id = "custom_settings",
* label = @Translation("Custom Settings"),
* storage = "config",
* translatable = true,
* fields = {
* "welcome_message" = {
* "type" = "textfield",
* "title" = "Welcome Message",
* "description" = "A message shown on the home page."
* },
* "featured_node" = {
* "type" = "entity_autocomplete",
* "target_type" = "node",
* "title" = "Featured Content"
* }
* }
* )
*/
class YourPluginName extends SiteConfigPluginBase {
}id: Unique identifier for the plugin.label: Human-readable label for the configuration group.storage: Eitherconfig(Configuration API) orstatus(State API).translatable: Boolean indicating if the values should be stored per language.fields: An array of form elements. Most standard Drupal Form API properties are supported.
Exposes the configurations via Drupal's RESTful Web Services.
- Resources:
site_config_list: List all available configuration sets.site_config_item: Get values for a specific configuration set.
Exposes the configurations as JSON:API resources.
- Endpoints:
/ jsonapi / site - config: List all configuration sets./ jsonapi / site - config / item / {id}: Get values for a specific config ID.
This module is licensed under the GPL-2.0-or-later license.