Skip to content

Instantly share code, notes, and snippets.

View mglaman's full-sized avatar

Matt Glaman mglaman

View GitHub Profile
@mglaman
mglaman / drops-release.sh
Created May 19, 2016 16:10
Script to package a Pantheon upstream once packaged on Drupal.org.
#!/bin/sh
DISTRO='commerce_kickstart'
NAME='Commerce Kickstart'
# @todo use REST API to get https://www.drupal.org/api-d7/node/2729399.json but by checking type and field_release_vcs_label
# this lets us know when it has been packaged.
git fetch upstream && git merge upstream/master
rm -rf profiles/$DISTRO
[
{
"command": "settings",
"settings": {
"ajaxPageState": {
"theme": "bartik",
"libraries": "bartik\/global-styling,classy\/base,classy\/messages,color_field\/color-field-formatter-swatch,commerce\/drupal.commerce.toolbar,commerce_cart\/cart_block,commerce_product\/rendered-attributes,commerce_product\/rendered-attributes,contextual\/drupal.contextual-links,contextual\/drupal.contextual-toolbar,core\/drupal.active-link,core\/html5shiv,core\/normalize,quickedit\/quickedit,shortcut\/drupal.shortcut,system\/base,toolbar\/toolbar,toolbar\/toolbar.escapeAdmin,tour\/tour,user\/drupal.user.icons"
},
"ajaxTrustedUrl": {
"form_action_cc611e1d": true,
@mglaman
mglaman / hook_update_N_helper.php
Last active March 1, 2016 21:56
Example using config_update to help automate hook_update_N for new config in config/install, or non-overridden config already active.
<?php
function example_helper_to_import_config_in_hook_update_N() {
/** @var \Drupal\config_update\ConfigReverter $updater */
$updater = \Drupal::service('config_update.config_update');
try {
$updater->import('commerce_product_type', 'dvds');
}
catch (\Drupal\Core\Entity\EntityStorageException $e) {
@mglaman
mglaman / mymodule.php
Created February 25, 2016 14:45
Loops through your custom module and ensures the config on hook_rebuild. Features like behavior, sans-Features.
<?php
/**
* Implements hook_rebuild().
*/
function mymodule_core_rebuild() {
$collection = \Drupal\Core\Config\StorageInterface::DEFAULT_COLLECTION;
$config_manager = \Drupal::service('config.manager');
$modules = ['custom_module1', 'custom_module2', 'custom_module3'];
foreach ($modules as $module) {
about:
command: about
aliases: { }
description: 'Display basic information about Drupal Console project'
synopsis: about
usages: { }
help: null
arguments: { }
options: { }
'cache:rebuild':
@mglaman
mglaman / instructions.txt
Created January 17, 2016 18:22
TL;DR for rebasing a fork.
> $ cd /path/to/your/fork
> $ git remote add upstream [email protected]:MidCamp/midcamp-website.git
> $ git fetch --prune upstream
> $ git rebease upstream/develop
> $ git push origin develop
@mglaman
mglaman / inbound_outbound.php
Last active January 16, 2016 20:45
Messing with inbound/outbound
<?php
/**
* Implements hook_url_inbound_alter().
*/
function muimodule_url_inbound_alter(&$path, $original_path, $path_language) {
if (preg_match('/^(.*)\/news$/', $path, $matches)) {
$node_path = $matches[1];
$conditions = array('alias' => $node_path);
$actual_apth = path_load($conditions);
(function ($) {
Drupal.behaviors.datePicker = {
attach: function (context, settings) {
var $fieldDate = $('form-item-attributes-field-date', context);
var $fieldDateSelect = $fieldDate.find('select', context);
var $fieldDateOptions = $fieldDate.find('option', context);
// Insert datepicker div
$('<div id="datepicker" />').insertBefore('.form-item-attributes-field-date');
<?php
// HINDSIGHT: Don't use presave. You'd need save (right, that exists?)
function mymodule_commerce_customer_profile_save($profile) {
if (isset($profile->my_custom_boolean)) {
// Okay so the field was set, or exists on this bundle.
if (!empty($profile->my_custom_boolean[LANGUAGE_NONE][0])) {
// Okay, we have a value (double check this var)
variable_set('commerce_addressbook_defaults', $profile->id);
}