When manipulating configuration yaml files in config/sync, I note that if you put files in subdirectories, and run drush config:import, the files in those subdirectories are denoted as belonging to a 'collection'. (Top-level files have no collection listed)

This seems like it might be a useful organisational unit. However, it seems like configurations that are part of a collection are not acted on.

For example, if I put a node.type.test.yml in config/sync, and run drush config:import then a corresponding node type is created as expected. However, if instead I put the file in config/sync/test and run drush config:import, then no type is created.

What is the purpose of these collections? Is there some way to indicate that you want collections to be activate/inactive within the configuration? Do they serve some completely different purpose?

  • 2
    Because you can define different configuration directories for multisite or environments. The default location Drupal looks is “config/sync”. You can define multiple and tell it where to look with additional parameters to the drush command. – Kevin Feb 18 at 17:54
  • 2
    Ok, but the config files in the subdirectory are still imported into the config table for the site that uses the parent directory for its configuration - they're just marked as belonging to a collection. Whereas files in a completely separate directory are naturally ignored. Surely files intended for a separate site or environment would be just ignored, rather than imported and then ignored? – Chris Feb 18 at 18:01

Collections are for configuration overrides. Mainly used for translations, but could be used for other purposes as well. You can list the available collections in your Drupal installation, starting with the default collection (empty string):

$collections = \Drupal::service('config.manager')->getConfigCollectionInfo()->getCollectionNames();

More info https://www.drupal.org/node/2268523

  • Right, so you can access the configurations in the collection programmaticly, but core will not use them at all? – Chris Feb 19 at 12:24
  • Yes, core only uses the collections listed with the command above. You can access the overridden values of your own collection with \Drupal::service('config.storage')->createCollection($collection)->read('node.type.test') or if you want to use it in a proper way extend ConfigFactoryOverrideBase, then your collection will be included in this list and can be discovered by other modules. – 4k4 Feb 19 at 13:21

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .