6

I have a config/install/module_name.settings.yml with some configuration values needed for my module. Now while developing the code I need to change or add values to the file. But for the script to be able to access the information I need to deinstall and install the module each time.

Is this normal?

I guess the yml file is just read on install; afterwards, the values are stored in database.

How should I store configuration data without needing to reinstall the module each time?

1 Answer 1

7

This is normal, because if the user modifies the settings, he doesn't expect that the changes are overwritten by a module update.

If you want to change the settings in an update hook, you can use the config API.

\Drupal::configFactory()->getEditable('mymodule.settings')->set('mysetting', $value)->save();

In development you can export the complete config of your site once to the sync folder. There you will find the yml file: /sites/default/files/config_hash/sync/module_name.settings.yml.

Edit the yml file in the sync folder and import the config as often as you want until you find the final version. After you've finished the development you can copy the final version of the settings yml in the module folder.

For export and import you can either use the admin configuration interface or use drush config-export and drush config-import.

Another option is to directly edit the config on the command line:

drush config-edit module_name.settings

After closing the editor the settings are imported in the active config. After you've finished the development open the settings one more time and copy and paste the end result in the yml file of your module.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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