Skip to content

Instantly share code, notes, and snippets.

@heyMP
heyMP / backupprod.sh
Last active December 28, 2015 21:49
Bash script for pulling product database down to local environment and one for pushing live database over to dev environment.
#!/bin/bash
drush @yoursite.prod archive-dump
rsync -rvz -e 'ssh -p 1855' --progress --remove-sent-files [email protected]:/home/yourusername/drush-backups /Users/yourusername/Documents/Websites/backups/productionserver
@heyMP
heyMP / gist:7570414
Last active December 28, 2015 22:19
Two methods of working with preprocess variables
// Altering the render array
function YOUR_THEME_preprocess_field(&$variables) {
//Giveaway node: field giveaway value
//change to dollar format
if ($variables['element']['#field_name'] == 'field_giveaway_value') {
$dollar_value = money_format('$%i', $variables['element']['#items'][0]['safe_value']) . "\n";
$variables['items'][0]['#markup'] = $dollar_value;
}
}
@heyMP
heyMP / gist:7681100
Created November 27, 2013 18:52
Using Entity Wrapper to easily save yo entities.
function _update_multi_registration($flag, $entity_id, $status) {
$entity_type = $flag->entity_type;
$entity = entity_load_single($entity_type, $entity_id);
$nodewrapper = entity_metadata_wrapper($entity_type, $entity);
$nodewrapper->field_event_mult_reg = $status;
$nodewrapper->save(true);
}
@heyMP
heyMP / gist:7845915
Created December 7, 2013 17:39
Logging a formatted Array to watchdog so it's readable. For development/debugging purposes only.
<?php
// Load up an array with variables you want to search through
$obj[] = $notification;
$obj[] = $invoice;
$obj[] = $user;
watchdog('module_name', 'Successfully Recieved Notification', array('@notification' => print_r($obj, 1)), WATCHDOG_NOTICE, 'link');
@heyMP
heyMP / gist:8201204
Created December 31, 2013 19:32
Adding a class attribute to an image in the render array.
sportsmans_hub_omega_preprocess_node(&$variables) {
$variables['content']['field_giveaway_image'][0]['#item']['attributes']['class'] = 'logo';
}
PROMPT='
$fg[cyan]%m: $fg[yellow]$(get_pwd)$(put_spacing)$(git_prompt_info)
$reset_color→ '
function get_pwd() {
echo "${PWD/$HOME/~}"
}
function put_spacing() {
local git=$(git_prompt_info)
@heyMP
heyMP / .zshrc
Created January 8, 2014 19:35
zsh aliases
#My aliases
alias ll="ls -la"
alias home="cd ~/"
alias websites="cd ~/Documents/Websites"
alias coda="/usr/local/bin/coda"
alias aurorawatch="bundle exec compass watch"
alias bashscripts="cd ~/Documents/Websites/bash_scripts"
@heyMP
heyMP / gist:8417971
Created January 14, 2014 13:04
Adding a destination parameter on the end of any link with drupal_get_desitnation(). You can add it to the links render array using #options.
$vars['edit_reg'] = array(
'#type' => 'link',
'#href' => 'field-collection/field-event-instance/' . $registration_id . '/edit',
'#title' => 'Edit',
'#alt' => 'Edit registrations.',
'#attributes' => array(
'class' => 'button',
),
'#options' => array('query' => drupal_get_destination()),
);
@heyMP
heyMP / template.php
Created January 17, 2014 20:16
Add the View Mode to the classes_array within your entity template. This is so we can theme specific view modes so we can easily switch between different layouts for the same entity using entity view modes
function template_preprocess_entity(&$vars, $hook) {
// Add the View Mode class to the classes_array
if (isset($vars['elements']['#entity_view_mode']['view_mode'])) {
$view_mode = $vars['elements']['#entity_view_mode']['view_mode'];
$vars['classes_array'][] = 'view-mode-' . str_replace('_', '-', $view_mode);
}
}
@heyMP
heyMP / child_margin_fixer.scss
Created February 10, 2014 21:39
Child Margin Fixer. This will remove the margin on the first child and last child elements within a selector. Mainly used for lists.
@mixin child-margin-fixer {
& > *:first-child,
& > *:last-child,
& > *:last-child > *:last-child,
& > *:last-child > *:last-child > *:last-child {
margin: 0;
}
}