Skip to content

Instantly share code, notes, and snippets.

@larowlan
Created August 4, 2020 06:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larowlan/79ad819ebb65363f3b8ea732223a28b1 to your computer and use it in GitHub Desktop.
Save larowlan/79ad819ebb65363f3b8ea732223a28b1 to your computer and use it in GitHub Desktop.
Create a missing block
/**
* Create a missing block (with empty fields but matching UUID).
*/
function yourmodule_post_update_create_a_missing_block() {
$block_entity_manager = \Drupal::service('entity.manager')->getStorage('block_content');
$missing_uuid = 'CE7DA6B0-C2A0-4EE9-8F6B-8854A3705FB7';
$block = $block_entity_manager->create([
'info' => 'Block title goes here',
'type' => 'block_type_machine_name_here',
'uuid' => $missing_uuid,
]);
$block->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment