1

I need to find out how to manually create a configuration file, one which will be included with a custom theme as optional/required upon installation.

I know I need to create a file in themes/mytheme/config/optional for a block, but how do I know the exact filename and what to put in it?

  • 2
    Don't write them, export them. Install your theme without them, then create the blocks in the UI, preferably with a common prefix on the ID, makes it easier. When you are done, export the configuration, take all blocks from your theme, put them in your config folder, remove uuid, done. @Clive The question alone might be too unspecific but it can be answered in a fairly specific way I think :) – Berdir Feb 15 '18 at 16:36
4

Creating configuration files manually is tedious and like @Berdir mentioned in the comments it is better to export them.

First install your theme, so you can place the blocks for your new theme.

  1. Create the blocks in the UI.
  2. Make sure you have installed the module: Configuration Manager (already installed if you use Standard profile)
  3. Export the configuration using the UI (/admin/config/development/configuration/full/export) or using Drush: drush cex
  4. Depending on how you exported the configuration:
    1. If you used UI, you have a .zip that you must extract.
    2. If you used Drush, the files are exported to sites/default/config_longname/sync
  5. The blocks file names are block.block.BLOCK_MACHINE_NAME.yml
  6. Copy those block files that you created and put them config/optional in your theme folder.
  7. Now open these files and remove the first line, looking something like: uuid: f95127a4-7947-48e3-a0f1-1dae6c61940d

That's it, if you move the theme to a new site and install the theme, the blocks will be installed and placed where you originally put them.

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.