How to copy blocks placement and settings between themes? suggests that, in Drupal 7, I could run the following two SQL queries to copy block placements and settings between themes.


INSERT INTO block (module, delta, theme, status, weight, region, custom, visibility, pages, title, cache, i18n_mode) (SELECT module, delta, 'NEW-THEME', status, weight, region, custom, visibility, pages, title, cache, i18n_mode FROM block WHERE theme = 'OLD-THEME')

What is the equivalent query/method I could use to achieve the same task in Drupal 8?

3 Answers 3


There is a module available for Block backup and restore. https://www.drupal.org/project/block_backup_restore


Drupal 8 block settings are in configuration files. It is possible to transfer them but takes a bit of editing / file renaming.

You first have to do a complete export of the configuration files. In this, the ones you are looking for have names like block.block....yml, e.g.: block.block.old_theme_main_menu.yml

First step is to rename these to block.block.new_theme...yml, e.g : block.block.new_theme_main_menu.yml. Generally a quick bit of editing to create a script to do the renaming is the easiest.

Next, you need to change the internal theme references to the old theme to the new theme. E.g. the old theme yml file will look like:

langcode: en
status: true
    - system.menu.main
    - block_class
    - system
    - old_theme
    classes: ''
id: old_theme_main_menu
theme: old_theme
region: navigation_collapsible
weight: -34
provider: null
plugin: 'system_menu_block:main'
  id: 'system_menu_block:main'
  label: 'Main navigation'
  provider: system
  label_display: '0'
  level: 1
  depth: 2
visibility: {  }

A good editor should be able to do a replace in files to change old_theme to new_theme. Double check that your theme names are unique in these files.

If the new theme does not have the same regions, then you will need to figure out how to change the region: setting to match your new theme.

In your new theme, create a config directory in the root and then an install directory under it.

Put all the yml files in the install directory.

Uninstall / re-install the new theme to import the settings here.

This assumes the same site with the same code / custom blocks.

If you are going to use this theme in a new site, you will have to make sure the site will provide the blocks defined in the yml config. Generally, the install directory is used to place system level blocks (e.g main menu) that core provides. But if you set up a system with a distro or manually to provide other blocks, this works as well.

There may be some minor gotcha's like visibility settings using the wrong node id and the like.


I was mostly successful in migrating about 500 blocks from one theme to the next by doing the following:

1. copy all block configs for old theme (eg block.block.theme1.*) to tmp directory
2. Removed configs that were disabled 'status: false'
3. bulk rename 500+ config files from theme1 to theme2 (need a tool for regex or partial string renaming, I used Windows PowerRename) 
4. Renamed same theme name strings within each file
5. Removed uuid from each file
6. Copied back into my sync directory and imported.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.