Understanding configuration in Drupal 8 is essential. It's a powerful tool that can streamline your development and deployment processes. After several rescue projects over the past year I have realised that the one thing that goes wrong first is the configuration. For some reason it's always left until last or even as an afterthought and this can really de-rail projects.
In this session I will cover.
How to get your configuration in and out of Drupal.
How to best manage your configuration.
Using configuration modules like Configuration Ignore and Configuration Split to manage your configuration across different platforms.
What to do when the client changes the configuration on your site and some other common problems that you might encounter.
Note: This presentation contained some videos that I couldn't translate into slideshare.
2. Phil Norton.
Blog at www.hashbangcode.com
Technical Lead
Access
Help run North West Drupal User Group
@philipnorton42
3.
4. Why Talk About Config?
➔ Access have taken on a few 'rescue' projects.
➔ Due to relationships breaking down with other agencies.
➔ Sites are a bit of a mess.
➔ Configuration always a problem
➔ Problems range from configuration not used to being used
once and forgotten.
➔ Is configuration hard?
6. What is config?
➔ Some things in Drupal are controlled by configuration.
➔ This governs how a site is put together.
➔ Modules can plug into this and define their own config.
➔ Configuration to be used to set up sites in a particular way.
7. Types Of Data In Drupal 8.
Content Blog post, Taxonomy terms etc.
Session Logged in status, shopping carts etc.
State Last cron run, API authentication details etc.
Configuration Everything else
31. Getting the configuration out of your site can be done in two
ways:
➔ Download direct from site
➔ Drush export
Exporting Configuration.
32. ➔ Configuration will need somewhere to live first.
➔ In order for Drush to export config it needs to know where
to put your config.
➔ Drupal also needs to know what directory to scan to pick
up your configuration.
Exporting Configuration.
33. Exporting
Config.
Create a directory that
your configuration will be
kept.
Best practice is to place
this outside the web root.
/config/default
/docroot/
/vendor/
41. Importing Config.
➔ Importing config will take whatever is in your configuration
directory and apply it to your site.
➔ This will override any settings you (or your users) have
changed.
➔ New configuration will be created.
➔ Deleted configuration will be removed*
* Drupal protects you from deleting config that contains content.
61. Working with configuration.
➔ After you install Drupal, export the configuration.
➔ Commit this to git straight away.
➔ Every change to the configuration can then be exported and
tracked in git.
➔ Allows you to see the changes you make.
➔ Makes collaboration much easier.
66. Production configuration.
➔ Your site users can alter production configuration through
using the site.
➔ Any configuration you import will overwrite existing
configuration on the site.
➔ Be careful not to overwrite your site configuration.
➔ Treat the production configuration as the single source of
truth.
➔ Always pull down your production configuration before
starting work.
68. Updates.
➔ Module updates may change config.
➔ When you update your code, run database updates and then
export the config.
➔ Then run database updates before importing config.
69. UUID?
➔ Every item of configuration gets a UUID.
➔ Every site is given a UUID (stored in system.site).
➔ This can occasionally cause problems with different streams
of configuration coming together.
➔ Solution here is to pick one.
70. Configuration Merge Conflicts?
➔ Rare, but it can happen.
➔ Ensure both streams of configuration are present.
➔ Do not manually alter your configuration.
➔ Test import and export of configuration.
72. Auto Install Config.
➔ Add configuration to a module so when it is installed that
configuration is applied to the site.
➔ Configuration files in module/config/install will be installed.
➔ Configuration files in module/config/optional will be
installed if all their dependencies are met.
76. Configuring Environments.
➔ What happens if you want to treat your staging environment
differently to your production environment?
➔ The Configuration Split module will split the configuration
into sections.
77. Configuration Split Use.
➔ Repoint an API to a sandbox environment on staging.
➔ Turn off emails on your staging environment.
➔ Disable development or UI modules on production.
➔ Turn on the Shield module for dev and staging
environments.
79. Configuration Split.
Complete / Blacklist
Configuration that only
exists in this split. It
doesn't exist in the
default configuration.
Conditional / Graylist
Configuration that exists
in the default
configuration, but which
is overridden on this site.
eg. config for modules
only enabled on this site
eg. API endpoints
86. Config
Split.
Dev is now set up.
/config/default
/core.extension.yml
/config/dev
/core.extension.yml
/dblog.settings.yml
/devel.settings.yml
/devel.toolbar.settings.yml
/field_ui.settings.yml
/system.menu.devel.yml
/views.view.watchdog.yml
/config/stage
/config/prod
87. Configuration Split.
➔ You can use drush cex and drush cim as you normally to
export and import the configuration.
➔ Just make sure you have the right configuration split set to
active when you do this.
92. Deployments.
➔ Be careful with deployments to ensure that the right site (and
environment) gets the right configuration imported.
➔ Activating configuration splits using logic is only half the
solution.
➔ You also need to inform Drush what site configuration you
want to import.
96. Configuration Ignore.
➔ The Configuration Ignore module allows Drupal to skip
certain parts of configuration when exporting or importing.
➔ Allowing a site (or split) to have a different configuration that
is not part of other configurations.
➔ Essential part of multi-site configuration setups.
98. Config Ignore.
➔ webform.webform.contact - ignore specific configuration.
➔ webform.webform.* - ignore any Webform in your site, but
not the generic webform.settings configuration.
➔ webform.webform.contact:status - ignore just that setting.
➔ ~webform.webform.contact - do not ignore configuration.
100. Preventing config changes.
➔ Lock all changes to any active configuration using the
Configuration Read-only Mode module
➔ Any item in configuration on disk will be locked.
➔ Useful if you want to prevent changes to certain this.
➔ Permissions, roles, site information, content types etc. are
good candidates for this.
104. Preventing config changes.
➔ You may want to allow some changes through.
➔ Configuration Ignore will allow this as the configuration won’t
be on disk.
➔ Configuration Read-only Mode has options to allow
configuration to be changed.
107. Content Block Placement.
➔ Content blocks are not in configuration.
➔ Their position on sites is in configuration.
➔ This creates an interesting problem where content is
required to work with the configuration present.
➔ There is no real solution to this currently.
➔ https://www.drupal.org/project/drupal/issues/2756331
108. Configuration Originates From A Different Site.
➔ If the UUID of your site differs from the value in
system.site.yml then Drupal will refuse to use it.
➔ Make sure you understand why this has happened.
➔ To get your site UUID from the database use this:
drush config-get "system.site" uuid
➔ To set your site UUID use this:
drush config-set "system.site" uuid "<value from
system.site.yml>"
109. Entities Stop Configuration Import.
➔ Drupal will stop the configuration importing if it detects a
destructive change.
➔ Ensure that your config isn't deleting anything that contains
content.
➔ Use update hooks to remove those entities before the
configuration is imported.
110. Disabled Module Configuration.
➔ If a configuration item for a module is in your configuration
but the module will not be enabled after config import.
➔ Can happen if a module was added or removed but the
core.extensions.yml file was not updated in git.
➔ Either remove the configuration item or ensure that the
module will be enabled via config.
111. Configuration Is Corrupted.
➔ Broken configuration can cause Drupal to crash.
➔ Missing references tends to be the main culprit.
➔ Use update hooks to sort out the configuration in the
database.
➔ Export the new configuration.
113. Everything at once.
➔ Drush - used to export and import configuration.
➔ Git - the gatekeeper of the configuration.
➔ Configuration Split - allows platform and multi-site setups.
➔ Configuration Ignore - allows splits to have special
configurations.
➔ Configuration Read-only Mode - prevents your users from
changing config.