Sync Blocks

How to Sync Blocks Between different environments in a Drupal 8 website

A custom block is made of two entities, one for the placement and one for the actual content. Only the actual placement can be exported with cim. The content can not. Therefore this will result in "Block description Broken/Missing" error on site where the config is imported. And since there is no option to disable custom blocks from being exported through Configuration management, this will break the functionality.

Steps to reproduce

On Site A:

Create custom block

Assign this custom block to any region

Export configuration of the site

On Site B:

Import configuration from site A

Go to Block layout and you will see custom block in correctly assigned region, however block won't work or actually show anything.

Edit that block, you will see this messages:

Block description Broken/Missing

   This block is broken or missing. You may be missing content or you might need to enable the original module.

Go under Custom block library and you won't see custom block.

Block layout got exported but block content didn't resulting in broken relationship.

Block In Local Instance

In the above image a drupal block named “Block Content test” is added in content region in a local instance.

Block In Dev Instance

The above image shows that the block is missing after importing configuration using Drush command “drush cim”.

Way 1: Using Database Sync

  1. Create Custom Block in Site B.

  2. Replace db of Site A with Site B using drush sql-sync

  3. Now the block is available in Site A. So will place it in a region.

  4. Use drush cex to export config and commit to Site B.

  5. Use drush cim in Site B and the block will be placed in the region.

Way 2: Use Drupal drush functions to export config and hook_update_n & block uuid to update content.

  1. Create block B4 Test in Site A.

  2. Place the block in some region.

  3. Export using drush cex.

  4. Commit and run drush cim in site B

  5. Block error will be shown in Site B

  6. Write hook_update_n and  commit. Take Update in Site B and run update.php in Site B to add the block.

  7. Check Site B if the block is placed or not.

We have used Drush Commands “drush cex” to export block configurations and “drush cim” to import the configurations.

So Once drush cim is done in site B write a hook_update_N in your custom module's .install file use the block uuid to update the database of Site B.

After running update.php the block will be placed in the region

The first method can be used where the database size is less as it will take less time to sync the database. The 2nd method can be used where the database size is huge.


Depending on the scenario we can use any one of the methods. In this blog I have explained the two methods which we can use for updating blocks from one environment to another.