Created
February 12, 2019 21:51
-
-
Save kbrinner/8feb781f92532a0d57365b484b0fa57f to your computer and use it in GitHub Desktop.
Programmatically delete blocks
This file contains hidden or 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
| /** | |
| * Delete unwanted blocks programmatically. | |
| * | |
| * @param array $blocks | |
| * Array of block UUIDs for deletion. | |
| */ | |
| function _delete_blocks(array $blocks) { | |
| foreach($blocks as $uuid) { | |
| $block_content = \Drupal::service('entity.repository')->loadEntityByUuid('block_content', $uuid); | |
| if (!is_null($block_content)) { | |
| $block_content->delete(); | |
| } | |
| } | |
| } | |
| /** | |
| * Delete unwanted blocks. | |
| */ | |
| function DEMO_helper_update_N() { | |
| $blocks_to_delete = [ | |
| '071d37ca-0157-4d50-a4a6-66ec7facc153', | |
| '16361ba0-a298-471b-a7cc-32f61873fb0d', | |
| '5681f213-6d9b-4bf5-9313-789c3c21ba5a', | |
| 'fb258b89-3f79-433a-95a7-9c437db81035', | |
| ]; | |
| _delete_blocks($blocks_to_delete); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment