Managing configuration

As we will see in a bit, Drupal stores configuration data in the database (for performance reasons), but it makes it all exportable to YAML files. So, a typical flow for managing it will have you perform changes in the UI, export the configuration, add it into Git, and deploy the code upstream to the next environment. There, it's just a matter of importing what is in code.

The import, export, and synchronization can be done both via Drush and through the UI at admin/config/development/configuration.

The typical flow is for the active site configuration to be synchronized with the one in the YAML files. This means importing into the database all the configurations that are different in the YAML files from those in the database. These YAML files are inside the configuration sync folder, which should be committed to Git (you can configure in the settings.php file which directory should be the sync folder) and the opposite is to export the active configuration to the YAML files in order to commit them into code.

The UI allows only the first option (sync what's in the YAML files with the database) but it provides you with a nice Diff interface to see what is different in YAML, as opposed to in the database:

In the preceding screenshot, we can see that the YAML files contain a small change in the site name configuration. Clicking on Import all will bring the database in line with the YAML files.

The first time you install a Drupal 8 site, the configuration sync folder will be empty. It is up to you to do a manual export of all the active configuration and put it there. You can do so via the UI manual export or through Drush:

drush config-export

You would do this step every time you make configuration changes through the UI that you want exported into YAML files.

Then, you can synchronize either in the UI as we've seen or through Drush:

drush config-import

As a Drupal developer, you will be mostly using these two Drush commands.

In addition to the entire set of configuration items, you can also import/export individual ones by copying and pasting. Be careful though, as some dependencies might not allow you to do so. However, this is useful if you want to quickly see something working in another environment, but the approach does not lend itself to a nice version-control-based flow if you abuse it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset