8

Is the MODULE.schema.yml required when you define the MODULE.settings.yml? It seems that it also works when I remove the MODULE.schema.yml file from install/schema.

10

It is not absolutely required but strongly recommended to have one.

By default, Drupal doesn't validate the schema, but it does in tests and there is an issue that will enable it if you use the provided example.settings.local.php/development.services.yml. That's why you don't see an error right now when you install, but you'll see it when you write your first test.

It is currently used to ensure the saved configuration has the right data type (e.g. a float and not an integer); not doing that correctly can break stuff and the ability of translating the configuration. More things might follow later, for example a module that generates a settings form.

1

The settings.yml is only needed when you want to have default values to start with in your config after the module is installed.

  • schema.yml has absolutely nothing to do with database tables, you mean hook_schema(). – Berdir Jan 12 '17 at 7:22
  • You are right I got them confused, I edited my answer – Fons Vandamme Jan 12 '17 at 8:48
1

MODULE/config/install/MODULE.settings.yml file is not mandatory.

MODULE.settings.yml file is basically used for configure default values. and that will only affect when you install module first time.

Two options available for reflect changes in MODULE.settings.yml:

  1. Uninstall MODULE and Install it again!
  2. Use MODULE.install file and hook_update_N(&$sandbox)

e.g. Filename: MODULE/MODULE.install

    /**
     * Write a line or two here about what the updates are for.
     * This is shown to users on the update.php page.
     */
    function mymodule_update_8001(&$sandbox) {
      $config_factory = \Drupal::configFactory();
      $default_value = 'Test';
      $config_factory->getEditable('MODULE.settings')->set('config_field_key', $default_value)->save();
    }

Reference Link

  • Do you mean that it is necessary to uninstall the module and install again if the settings.yml updated? – Jahng Jan 12 '17 at 9:53
  • Please check my updated answer, I hope it will help you. – AshwinP Jan 12 '17 at 10:56

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.