Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sdeering/56a00ebb33635c7ad08d4e1d4d97d2c0 to your computer and use it in GitHub Desktop.
Save sdeering/56a00ebb33635c7ad08d4e1d4d97d2c0 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* DB post-updates for blocks.
*/
use Drupal\block_content\Entity\BlockContent;
/**
* Create empty custom block content for new blocks that require them.
*/
function theme_blocks_post_update_2019_10_22(&$sandbox) {
createBlockIfNotExists([
'type' => 'block_type',
'uuid' => '11ee98a0-2cd1-4285-a787-9c57117cfa66',
'info' => 'block description...',
]);
}
function createBlockIfNotExists($block) {
if (!blockExists($block['uuid'])) {
BlockContent::create($block)->save();
}
}
function blockExists($blockUuid) {
return \Drupal::entityTypeManager()->getStorage('block_content')->loadByProperties(['uuid' => $blockUuid]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment