Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Crittenden mikecrittenden

View GitHub Profile
@mikecrittenden
mikecrittenden / MODULENAME.module.php
Last active Oct 23, 2020
Add a query_args cache context to the header block so that the cache is dependent on query string.
View MODULENAME.module.php
<?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';
}
}
@mikecrittenden
mikecrittenden / import.js
Last active Sep 3, 2020
Parse and import a JS array into neo4j via the neo4j-driver
View import.js
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) => {
@mikecrittenden
mikecrittenden / outline.md
Last active Oct 13, 2020
Difficult Conversations outline
View outline.md

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.
@mikecrittenden
mikecrittenden / MODULENAME.module.php
Created Jun 7, 2020
Use Drupal 8 block region in template suggestions
View MODULENAME.module.php
<?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'];
}
@mikecrittenden
mikecrittenden / MODULENAME.install.php
Created Jun 7, 2020
Drupal 8: Update allowed values of a select field
View MODULENAME.install.php
<?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', [
@mikecrittenden
mikecrittenden / test.php
Created Jun 7, 2020
Rebuild taxonomy_index table for all nodes
View test.php
<?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); 
@mikecrittenden
mikecrittenden / modulename.install.php
Last active Oct 19, 2020
Uninstall Multiversion and Workspace from Drupal 8. This is an update hook which successfully uninstalled the module from our fairly complicated site.
View modulename.install.php
<?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,
View test.json
{"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
View push-to-pantheon.sh
#!/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
View push-to-pantheon.sh
#!/bin/bash
## Push the local site to the Pantheon repo
yellow='\033[1;33m'
NC='\033[0m'
cd "$PROJECT_ROOT"
echo
You can’t perform that action at this time.