Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Crittenden mikecrittenden

View GitHub Profile
@mikecrittenden
mikecrittenden / outline.md
Last active Aug 5, 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 Jul 28, 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
View EntityReferenceMultipleFormatter.php
<?php
namespace Drupal\entityreference_multiple\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter;
/**
* Plugin implementation of the 'entityreference_entity_multiple_view' formatter.
View menu-local-task.html.twig
{#
/**
* @file
* Theme override for a local task link.
*
* Available variables:
* - attributes: HTML attributes for the wrapper element.
* - is_active: Whether the task item is an active tab.
* - link: A rendered link element.
*
You can’t perform that action at this time.