With the new Configuration Management System we can create a module.settings.yml file with all the variables that we will use in our module.

Now just to made a test I delete all the content inside my module.settings.yml file (leaving the file empty), I reinstalled the module and it works, so I deleted my module.settings.yml file and I reinstalled my module one more time and, the module works, I can set the variables (the configuration is created) and I can use the variables, even I can export the configuration.

In this scenario I see that you don't need to define your variables even the file is not needed (or maybe I missing something). So, should I define all my variables in the module.settings.yml file?


Talking of the configuration file in config/install, its purpose is setting the default values for the configuration used from the module.

Deleting its content could probably not make much difference if the default values are FALSE, NULL, or an empty string. In the other cases, its content would make a difference.

  • In my case is a string array, and the module works perfect without having the file the config/install directory. Apr 10 '17 at 15:53
  • Ohh I just read this again and I note that you says: "its purpose is setting the default values for the configuration used from the module" I thought that his function is to define the variables that will be used by the module. Can you provide me some references about this? Apr 10 '17 at 15:59
  • I found here drupal.org/docs/8/api/configuration-api/… this: "An extension (module, theme, or profile) that provides default values for its configuration must put that configuration into YAML files in its config/install sub-directory." So, is not mandatory to define the settings.yml file? Apr 10 '17 at 16:04
  • I was referring to what reported in api.drupal.org/api/drupal/core%21core.api.php/group/config_api/…. As far as I can say, it is not mandatory. The configuration schema is something highly recommended, though.
    – apaderno
    Apr 10 '17 at 16:37

I guess you don't need it if your variables are optional. If you have required variables or if you just want to provide default variables put it in a module.settings.yml file within a config/install folder.

  • I use the variables to save module configurations, so the first time I install the module I don't need the variables. Apr 10 '17 at 15:02

Drupal Docs update

In Drupal Docs there is an explanation of how to configuration, Structure, get and edit module_name.settings file in config/install subdirectory of your module directory as here: Defining and using your own configuration in Drupal 8 as follow:

The simplest way to use this is the Drupal::config() static method:

$config = \Drupal::config('example.settings');
// Will print 'Hello'.
print $config->get('message');
// Will print 'en'.
print $config->get('langcode');

If you want to edit a configuration and update it with a new value you can use the \Drupal::service('config.factory')->getEditable() method:

$config = \Drupal::service('config.factory')->getEditable('example.settings');

// Set and save new message value.
$config->set('message', 'Hi')->save();

// Now will print 'Hi'.
print $config->get('message');

To know more please read it. The best part it explains how to make your settings translatable using langcode key and including two more files example.schema.yml and example.config_translation.yml.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.