Skip to content

Instantly share code, notes, and snippets.

View crittermike's full-sized avatar

Mike Crittenden crittermike

View GitHub Profile
@crittermike
crittermike / MODULENAME.module.php
Last active October 23, 2020 17:43
Add a query_args cache context to the header block so that the cache is dependent on query string.
<?php
function MODULENAME_block_build_alter(array &$build, \Drupal\Core\Block\BlockPluginInterface $block) {
// Add the 'query args' cache context to the header block.
if ($this_block_is_the_header_block) { // @TODO: Make this line work.
$build['#cache']['contexts'][] = 'url.query_args';
}
}
@crittermike
crittermike / import.js
Last active September 3, 2020 18:23
Parse and import a JS array into neo4j via the neo4j-driver
const session = driver.session()
const query = `WITH $data AS values
UNWIND values AS item
MERGE (thing:Thing {id: item.id})
SET thing.title = item.title`
session
.run(query, { data: yourArrayHere })
.catch((error) => {
@crittermike
crittermike / outline.md
Last active January 6, 2022 21:38
Difficult Conversations outline

Step 1: Prepare by Walking Through the Three Conversations

  1. Sort out What Happened.
  • Where does your story come from (information, past experiences, rules)? Theirs?
  • What impact has this situation had on you? What might their intentions have been?
  • What have you each contributed to the problem?
  1. Understand Emotions.
@crittermike
crittermike / MODULENAME.module.php
Created June 7, 2020 03:28
Use Drupal 8 block region in template suggestions
<?php
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function THEMENAME_theme_suggestions_menu_alter(array &$suggestions, array $variables) {
if (isset($variables['attributes']['region'])) {
// Add a template suggestion based on region name
$suggestions[] = $variables['theme_hook_original'] . '__' . $variables['attributes']['region'];
}
@crittermike
crittermike / MODULENAME.install.php
Created June 7, 2020 03:26
Drupal 8: Update allowed values of a select field
<?php
/**
* Update allowed values of background color field.
*/
function MODULENAME_update_8001(&$sandbox) {
// Load the field.
$field_config = FieldStorageConfig::loadByName('node', 'field_card_view_background_color');
// Update the allowed values on it.
$field_config->setSetting('allowed_values', [
@crittermike
crittermike / test.php
Created June 7, 2020 03:22
Rebuild taxonomy_index table for all nodes
<?php
$query = \Drupal::entityQuery('node');
$ids = $query->accessCheck(FALSE)->execute();
$storage_handler = \Drupal::entityTypeManager()->getStorage('node');
// If you have a lot of nodes, you may have to split this up via
// array_chunk() instead of trying to load all nodes at one time.
$entities = $storage_handler->loadMultiple($ids);
foreach ($entities as $entity) { 
taxonomy_build_node_index($entity); 
@crittermike
crittermike / modulename.install.php
Last active January 14, 2021 06:08
Uninstall Multiversion and Workspace from Drupal 8. This is an update hook which successfully uninstalled the module from our fairly complicated site.
<?php
/**
* Uninstall Multiversion and related modules.
*/
function modulename_update_8000() {
// !!! IMPORTANT !!!
// First, make sure to check and see if any of the below entities have a
// value of NULL in "_deleted" or "workspace" columns, because if so,
{"team_allianceBernstein":{"teams":[{"title":"Chris Hogbin","fr_id":3392,"px_id":4436801,"extreme":true,"goaldollars":"22000","dollars":"21690","url":"http://mskcc.convio.net/site/TR?pg=personal&px=4436801&fr_id=3392","id":1,"event_team_fields":[{"name":"location","label":"Location/Shift","enabled":true,"value":"NYC All Extreme Ride, AM shift 8AM-12PM on November 9","$$hashKey":"object:15"},{"name":"captain","label":"Team Captain","enabled":false,"value":"","$$hashKey":"object:16"},{"name":"numRiders","label":"# of Riders","enabled":false,"value":"","$$hashKey":"object:17"}]},{"title":"Brian Holland","fr_id":3392,"px_id":4099491,"extreme":true,"goaldollars":"5000","dollars":"4950","url":"http://mskcc.convio.net/site/TR?pg=personal&px=4099491&fr_id=3392","id":2,"event_team_fields":[{"name":"location","label":"Location/Shift","enabled":true,"value":"NYC All Extreme Ride, AM shift 8AM-12PM on November 9","$$hashKey":"object:22"},{"name":"captain","label":"Team Captain","enabled":false,"value":"","$$hashKey":"obj
#!/bin/bash
yellow='\033[1;33m'
NC='\033[0m'
cd "$PROJECT_ROOT"
echo
echo -e "${yellow}Cloning Pantheon repo...${NC}"
git clone ssh://codeserver.dev.f5ee6474-0663-441f-8ef0-9f5f54e427d4@codeserver.dev.f5ee6474-0663-441f-8ef0-9f5f54e427d4.drush.in:2222/~/repository.git pantheon-codebase
#!/bin/bash
## Push the local site to the Pantheon repo
yellow='\033[1;33m'
NC='\033[0m'
cd "$PROJECT_ROOT"
echo