Skip to content

Instantly share code, notes, and snippets.

View kbrinner's full-sized avatar

Kristin Brinner kbrinner

  • Solana Beach CA
View GitHub Profile
@kbrinner
kbrinner / delete_blocks.php
Created February 12, 2019 21:51
Programmatically delete blocks
/**
* 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)) {
@kbrinner
kbrinner / import_configs.php
Created February 12, 2019 21:51
Programmatically import configs
/**
* Import configs that may be needed for any further updates.
* These files should be placed in config/install/[update_id] in this module for initial
* installation. The configs should also be placed in /config/default for all future
* modifications.
*
* Based on https://stackoverflow.com/a/52277490/1650120.
*
* @param string $update_id
* The name of the folder in containing the yml files.
@kbrinner
kbrinner / create_content.php
Created February 12, 2019 21:50
Create content programmatically
/**
* Creates install content.
*
* @param array $content
* Content keyed by entity-type and UUID.
*
* @return array
* An array of entities created, keyed like the parameter.
*/
function _create_content(array $content) {