Created
October 22, 2019 00:14
-
-
Save sdeering/56a00ebb33635c7ad08d4e1d4d97d2c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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