Drupal update hook to deploy block configuration

Part of my series of blog posts on Useful Drupal update hooks

There's no way in Drupal core to export block configuration settings to Features and get it into version control, so I often use a snippet like the following in order to deploy changes to blocks. Essentially it just boils down to an upsert query on the blocks table using theme, delta and module as the keys, and you can then update any of the other values in this table in the fields() method. The call to _block_rehash is simply there to make sure the blocks table is up to date with any blocks exported by modules. It's often not necessary but is handy if your update hook is going to run and modify information about a new block that didn't exist before the current deployment.

Tags