29

Is it possible to import one single configuration file by specifying its path, or a group of Yaml files contained in a specific module?

  • You can by enabling the config module and then using the single import page. – user21641 Nov 28 '16 at 9:11
  • Thanks @IvanJaros, can you expand the comment to an answer with details how to enable the config module and the path to the single import page? Is there any way to achieve the same results with drush or drupal console? If it works, I'll accept the answer. Cheers! – David Riccitelli Nov 28 '16 at 9:37
  • i guess you can put the file into config/sync directory and just run drush cim, ive always used ui for single config file. – user21641 Nov 28 '16 at 9:42
  • That would import all the files in the sync directory. – David Riccitelli Nov 28 '16 at 12:40
22

You can use

$ drush cim --partial --source=only-few-configs/

Your help says:

$ drush cim --help
Import config from a config directory.

Examples:
 drush config-import --partial             Import configuration; do not remove missing configuration.

Arguments:
 label                                     A config directory label (i.e. a key in $config_directories array in 
                                           settings.php). Defaults to 'sync'

Options:
 --partial                                 Allows for partial config imports from the source directory. Only updates and new 
                                           configs will be processed with this flag (missing configs will not be deleted).   
 --preview=<list>                          Format for displaying proposed changes. Recognized values: list, diff. Defaults   
                                           to list.                                                                          
 --source                                  An arbitrary directory that holds the configuration files. An alternative to      
                                           label argument

Aliases: cim
| improve this answer | |
  • 7
    That's great, but if you want to import one file you have to move it to another partial directory? That's weird, isn't it? – rreiss Jul 24 '18 at 7:53
  • 1
    If running in Lando/Docker, prefix the directory path with /app/ (as suggested in the Drupal Console answer). – colan Apr 21 at 16:37
  • @rreiss agree, spot on. +1 Seems another example of an obvious usability that gets overlooked and a detatchment of reality the makers of these tools from what people need. – therobyouknow Aug 25 at 16:51
  • I came here because I can't be sure that core.extension.yml is running before the other config that depends on it is running. I keep getting errors about PlugIns (i.e. Drupal contrib modules) not existing. So I want to import core.extension.yml first hence the need to import just this file. – therobyouknow Aug 25 at 16:55
  • Actually, I don't think I need this solution in this answer but thank you anyway, good to know! I did manage to put the config file in a separate directory and run this command. My issue - ( Unable to install the ... ... module since it does not exist.) - was solved here by another solution: drupal.org/project/drupal/issues/3100026#comment-13800827 – therobyouknow Aug 26 at 9:00
17

You can import one configuration by running the following command:

 drupal config:import:single

If you are trying to run multiple import you can create a chain for that.

Command Documentation - config:import:single

| improve this answer | |
  • 5
    Is there an option for drush aswell? – Benedikt Oct 16 '17 at 7:10
  • 7
    Tip for Lando/Docker users - you need to specify the full path when running in a container, e.g. drupal config:import:single --directory="/app/config/sync" --file="foo.settings.yml", rather than just config/sync when you are in /app - otherwise you'll get [ERROR] Value can not be empty. (Fortunately Drupal Console's source code is nice and easy to debug.) – William Turrell Jul 25 '18 at 5:55
  • This is fantastic. Note that it didn't like working for me using lando, I had to lando ssh so the machine first and then run it natively. – Christian Jul 28 at 3:32
4

In case you don't have Drush or Drupal console installed, please use the following steps (executed successfully in D 8.0.1):

  1. Go to Administration->Configuration->Configuration Synchronization. Configuration can be exported for a single item or for entire site. I did for a single user.mail.yml file. Export the required configuration.
    1. Modify the changes to the exported configuration.
    2. Import the modified configuration
    3. Once import is successful, ensure that you clear the existing data from config and cache_config tables(Extract a dump of the database and search for the configuration keywords. That way you will know the tables where the entry is present.)

Note - Always take a backup.

| improve this answer | |

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.