Skip to content

Instantly share code, notes, and snippets.

View reinette's full-sized avatar

Renée reinette

  • confluent.io
  • SF, Vancouver, The World
View GitHub Profile
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
_tcaq.push(['capture', 'event', {'person_udf9':'segment1,segment2,segment3'}]);
_tcaq.push(['captureIdentity','user@example.com','email']);
@reinette
reinette / EntityManagerDecorator.php
Last active December 1, 2017 20:45
Decorate the Content Hub service to be a bit more strict about what is added to the Hub.
<?php
namespace Drupal\custom_contenthub;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\acquia_contenthub\Client\ClientManagerInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
@reinette
reinette / d8-fieldapi-tricks.txt
Created January 30, 2017 19:05 — forked from eaton/d8-fieldapi-tricks.txt
Drupal 8 field wrangling
// Check whether a node's bundle has a particular field
if ($node->hasField('field_might_be_missing')) { ... }
// Check field-type-specific empty/not empty logic
if ($node->field_name->isEmpty()) { ... }
// Iterate over individual instances in a field. field_name isn't an actual
// array, but a special iteratable class, so it won't die if the field is empty.
foreach ($node->field_name as $delta => $field_instance) { ... }
@reinette
reinette / gist:7649ab08df3d3e0865008966c1388698
Created January 25, 2017 17:24 — forked from benclark/gist:3974958
SQL snippet for estimating Drupal cache table sizes
-- Use this query when preparing to move cache tables into memcache bins
-- to estimate how big the bins should be (or how many will be necessary).
SELECT count(*) tables,
concat(round(sum(data_length)/(1024*1024),2),'M') data,
concat(round(sum(index_length)/(1024*1024),2),'M') idx,
concat(round(sum(data_length+index_length)/(1024*1024),2),'M') total_size
FROM information_schema.TABLES
WHERE table_schema LIKE '<<DRUPAL DATABASE NAME>>'
AND table_name like "cache%"
-- Exclude any cache tables you know won't be in memcache:
@reinette
reinette / README.md
Created January 1, 2017 06:06 — forked from Greg-Boggs/README.md
Drupal Site Building Best Practices

Better Drupal Building

  • Custom glue should be accomplished with configuration first and PHP code second.

Configuration Management and Dependencies

  • Use Composer (or Drush Make) to build your project and it's depencies.
  • Store your work in files.
  • Set your config directory above the webroot.
  • Sync UUIDs across all developers.

Theming

@reinette
reinette / gist:2720f32125dbceed071b
Last active November 2, 2015 05:41
CTools Automodal Admin support for ECK entities - custom submit handler
function mymododule_form_alter(&$form, &$form_state, $form_id) {
//dpm($form_id, __FUNCTION__);
// Check if node form is automodal.
// If it is, add own submit function.
// Note, full ECK form pattern is: eck__entity__form_(add|edit)_myentity_mybundle
if(preg_match('/eck__entity__form_(add|edit)_myentity_*./', $form_id)) {
// Check if it's ajax request
if (isset($_POST['js']) || isset($_POST['ajax_html_ids'])) {
$form['actions']['submit']['#submit'][] = 'prefs_helper_submit_entity';
}
domain_access_er_select_all.module
<?php
/**
* Implements hook_ctools_plugin_directory().
*/
function domain_access_er_select_all_ctools_plugin_directory($module, $plugin) {
if ($module == 'entityreference') {
return "plugins/entityreference/$plugin";
}
}