Skip to content

Instantly share code, notes, and snippets.

View quicksketch's full-sized avatar

Nate Lampton quicksketch

View GitHub Profile
@quicksketch
quicksketch / YAML v. JSON
Created September 14, 2013 19:38
YAML vs. JSON decoding against Drupal config files.
<?php
require_once __DIR__ . '/core/vendor/autoload.php';
require_once __DIR__ . '/core/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
use Symfony\Component\Yaml\Parser;
$parser = new Parser();
$yaml_files = file_scan_directory('./test_yaml', '/\.yml$/');
@quicksketch
quicksketch / benchmark_yaml.php
Created September 15, 2013 01:40
Comparing spyc vs. Symfony vs. JSON parsing
<?php
require_once __DIR__ . '/core/vendor/autoload.php';
require_once __DIR__ . '/core/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
$yaml_files = file_scan_directory('./test_yaml', '/\.yml$/');
$start = microtime(TRUE);
$yaml_contents = array();
@quicksketch
quicksketch / format_benchmarks.php
Created September 16, 2013 00:09
Symfony YAML vs. Spyc YAML vs. JSON vs. PHP parsing times.
<?php
require_once __DIR__ . '/core/vendor/autoload.php';
require_once __DIR__ . '/core/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
$yaml_files = file_scan_directory('./test_yaml', '/\.yml$/');
$start = microtime(TRUE);
$yaml_contents = array();
@quicksketch
quicksketch / drupal.inc
Last active December 26, 2015 02:19
Sample drupal.inc file that demonstrates wrapping Drupal functions for backwards compatibility with Drupal 7 namespaces.
<?php
/**
* @file
* Contains constants and function wrappers for Drupal 7.x compatibility.
*/
/**
* @defgroup drupal_compatibility Drupal compatibility layer.
* @{
* These functions and classes are wrappers around Backdrop functions that allow
@quicksketch
quicksketch / gist:11124800
Last active February 28, 2016 08:22
Alter Webform outgoing e-mail
<?php
/**
* Implements hook_mail_alter().
*/
function mymodule_mail_alter(&$message) {
if ($message['id'] == 'webform_submission') {
// Use the From header as a Reply-to and set the From header to the site
// mail address. Trying to say e-mail is "From" other domains will get the
// mail marked as spam, so instead the e-mail is always from webform.com,
// but the reply address is the user-specified address.
@quicksketch
quicksketch / admin_menu_d7_diff.diff
Last active August 29, 2015 14:01
Admin Menu Backdrop Port
diff --git a/admin_menu.admin.js b/admin_menu.admin.js
index 9ee9f36..fea1a54 100644
--- a/admin_menu.admin.js
+++ b/admin_menu.admin.js
@@ -5,7 +5,7 @@
*/
Drupal.behaviors.adminMenuLivePreview = {
attach: function (context, settings) {
- $('input[name^="admin_menu_components"]', context).once('admin-menu-live-preview')
+ $('input[name^="components"]', context).once('admin-menu-live-preview')
@quicksketch
quicksketch / generic-site.conf
Created April 18, 2016 18:20
General setup instructions for Drupal/Backdrop on nginx
# Server configuration for example.com
server {
# Require HTTP authentication.
#auth_basic "Restricted";
#auth_basic_user_file /home/example/.htpasswd;
# Limit each user to 20 max connections.
limit_conn default 20;
# Set up ports and server address.
@quicksketch
quicksketch / dropdown.css
Created September 6, 2016 06:36
CSS/JS needed for Dropdown menus in Admin Bar
/* All dropdown list items */
#admin-bar .dropdown li {
background-image: none;
float: left; /* LTR */
height: 100%;
list-style-image: none;
list-style-type: none;
margin: 0 !important;
padding: 0;
@quicksketch
quicksketch / rename-field.php
Created March 27, 2018 20:42
Rename a Drupal 7 field machine name while maintaining field data
<?php
/**
* Rename field_resource_thumbnail to field_reference_thumbnail.
*/
function example_update_7001() {
_example_update_rename_field('field_resource_thumbnail', 'field_reference_thumbnail');
_example_update_rename_field('field_resource_short_description', 'field_reference_description');
}
@quicksketch
quicksketch / buildEntityFieldQuery.php
Last active April 26, 2018 21:29
How Entity Reference module builds its SQL query
<?php
/**
* Build an EntityFieldQuery to get referencable entities.
*/
protected function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', $this->field['settings']['target_type']);
if (!empty($this->field['settings']['handler_settings']['target_bundles'])) {
$query->entityCondition('bundle', $this->field['settings']['handler_settings']['target_bundles'], 'IN');
}