3

Some days ago I've exported and imported a full configuration with drush cex and drush cim.

What are the steps to export 1 paragraph type including the fields, form settings, display settings etc ...

I'm using a multisite, so it would be great to copy them from one site to the other sites within the multisite.

Can I:

  1. drush cex site 1
  2. copy exported .yml files to other site in folder (sites/site1.multisite.com/files/config_HASH/sync)
  3. Delete all .yml files except those needed for the import of my paragraph type?

I guess there are better methods to establish this?

  • Don't do that, drush cim deletes configs not present in the sync folder. Use a different folder and the --partial option. See drupal.stackexchange.com/questions/221592/… – 4k4 Oct 14 at 7:52
  • To copy config from one site to another you may have a look at the Features module. Export feature on one site, import it in another, export config on both sites, done. One feature always only contains the partial config you decide. – leymannx Oct 14 at 8:32
  • @4K4 good to know about the deletion. It looks like it is not that simple. I need to test this on a development site. – Lance Oct 14 at 8:37
  • With Features you also can easily keep track of changes and then sync them on the other site(s) again. – leymannx Oct 14 at 9:50
  • 2
    Does this answer your question? Import a single yml configuration file – 4k4 Oct 14 at 10:03
3

That's exactly what the Features module is for. Syncing partial config across multi-site instances.

The features module enables the capture and management of features in Drupal. A feature is a collection of Drupal entities which taken together satisfy a certain use-case.

Features provides a UI and API for taking different site building components from modules with exportables and bundling them together in a single feature module. A feature module is like any other Drupal module except that it contains additional information in its info file so that configuration can be checked, updated, or reverted programmatically.

That means you would create a feature on your main multi-site instance which contains the paragraph type. Have it placed inside the modules/features/ folder. Related config will be added automatically. You then enable the feature (which basically is just another module) in another multi-site instance. The config will be imported into the database. On both multi-site instances you then export config as usual. Because every multi-site instance still is managed from its own config. Which then also contains the synced paragraphs config.

As soon as you add another field to the paragraph type on either multi-site instance Features will recognise the changes. You then can recreate your paragraph feature and import the changes on another multi-site instance (into the database). Finally, on both sites again export config as usual (which then also contains the paragraph types you've synced via Features). Features enables you to keep track of changes to a feature via built-in diffing, which after you recreated the feature (partial config gets exported) can be synced into the database on other multi-site instances again.

Of course Features also comes with a set of Drush commands to make your live easier.

| improve this answer | |
  • "then export config as usual" please explain in more detail. Keep in mind that config in this case) is not equal on all the different sites within the multisite approach. – Lance Oct 14 at 12:02
  • @Lance – Yep, that's exactly why you manage each site from their own config (as usual). The Features module only is a helper to sync partial config into the database. From where it must be exported as site-dependant (normal) config. On live/prod then you leave the features untouched, you just import config (which then also contains the paragraph type on both sites). – leymannx Oct 14 at 12:05
  • So if I create a paragraph type on the main site (or other) then with Features you can manage to only export that specific paragraph type with all settings and import it into the other site? Without using drush cmd? I did not yet install the module, so it is a guess. – Lance Oct 14 at 12:13
  • 1
    @Lance – Exactly. Because features are just modules in the end. Of course Features also comes with a set of Drush commands to export and import changes. When exporting an updated feature the module will then be rewritten and you can then go to your other multi-site where Features will tell you, hey there are changes in the feature module which ain't active on that site here, do you want me to import them? They then can be imported into the active config of this instance's database. From where you export the instance-specific config as usual, because every instance still has its own config. – leymannx Oct 14 at 12:18
  • I have now both modules available on both sites (sounds logic in a multisite environment). I have only enabled the module on the site where I did not have the new content type. On the source sites I do not have to activate it right? – Lance Oct 14 at 14:58
1

Best way to do this is make custom modules and add the specific yml files to config/install. This way you can just enable the module on other websites.

A good way of working could be a custom module named custom_paragraphs with a .info file and a modules folder. Within this module all your submodules per paragraph type.

  • custom_paragraphs
    • custom_paragraphs.info.yml
    • modules
      • custom_paragraphs_two_column
        • custom_paragraphs_two_column.info (add dependencies here!)
        • config
          • install
            • (all the yaml files here)
      • custom_paragraphs_slider
        • ...

Update a module by using:

drush config-import --partial --source=modules/custom/custom_paragraphs/modules/custom_paragraphs_two_column/config/install
| improve this answer | |
  • That's exactly what Features does for you. – leymannx Oct 14 at 9:48
  • 2
    @leymannx, yeah but why need contrib for this? – Stef Van Looveren Oct 14 at 9:50
  • Because it takes care of all the manual work you need to do otherwise. It also enables you to easily keep track of changes via built-in diffing and sync capabilities when something changes. No need to reinvent the wheel in a way. – leymannx Oct 14 at 9:52
  • I see. Both are an option. Features also adds some complexity. – Stef Van Looveren Oct 14 at 9:56
  • 1
    @Lance create the paragraph "Two column" and export to your general configuration. Then, paste all the files containing filename two_column in the config/install folder of the custom submodule. Then enable the module on website 2. – Stef Van Looveren Oct 15 at 9:46

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.