1 block.install block_update_1004()

Move individual blocks into config files.

Related topics

File

core/modules/block/block.install, line 93
Install, update and uninstall functions for the block module.

Code

function block_update_1004() {
  if (!db_table_exists('block_custom')) {
    return;
  }

  $blocks = db_query("SELECT * FROM {block_custom}")->fetchAllAssoc('bid');
  foreach ($blocks as $block) {
    $block = (array) $block;
    $data = array(
      'delta' => $block['bid'],
      'info' => $block['info'],
      'title' => $block['title'],
      'body' => array(
        'value' => $block['body'],
        'format' => $block['format'],
      ),
    );
    $config = config('block.custom.' . $block['bid']);
    $config->setData($data);
    $config->save();
  }

  db_drop_table('block_custom');
}