Skip to content

Instantly share code, notes, and snippets.

View mglaman's full-sized avatar

Matt Glaman mglaman

View GitHub Profile
@mglaman
mglaman / menu_get_item_alter-custom-theme.php
Created March 11, 2014 22:09
Allows you to define a theme_callback and change default theme. Useful when using Admin theme for node/edit, but you want forums to use default.
<?php
/**
* Implements hook_menu_get_item_alter().
*/
function mymodule_menu_get_item_alter(&$router_item, $path, $original_map) {
if ($router_item['path'] == 'node/add/forum') {
$router_item['theme_callback'] = 'mymodule_menu_theme_callback';
}
}
@mglaman
mglaman / menu.inc-exerpt.php
Created April 15, 2014 04:13
Demonstrates why hook_custom_theme() never seems to apply, and why to use hook_menu_get_item().
<?php
/**
* Excerpt from menu.inc
* Lines 1745-1755
*/
// First allow modules to dynamically set a custom theme for the current
// page. Since we can only have one, the last module to return a valid
// theme takes precedence.
$custom_themes = array_filter(module_invoke_all('custom_theme'), 'drupal_theme_access');
<?php
/**
* Implements hook_preprocess_html().
*/
function mytheme_preprocess_html(&$variables) {
// IE EDGE SUPPORT
if (drupal_get_http_header('X-UA-Compatible') === NULL) {
drupal_add_http_header('X-UA-Compatible', 'IE=edge,chrome=1');
}
@mglaman
mglaman / html.preprocess.inc
Created April 19, 2014 03:55
Add FontAwesome.io to your Omega 4 subtheme
<?php
<?php
/**
* @file
* Includes preproces of html
*/
/**
* Implements hook_preprocess_html().
*/
@mglaman
mglaman / commerce_line_item_table_export.php
Created May 3, 2014 21:57
The Commerce line item table with a field that links to user profiles. Remember to make sure there are proper permissions for viewing a profile!
<?php
$view = new view();
$view->name = 'commerce_line_item_table';
$view->description = 'Display a set of line items in a table.';
$view->tag = 'commerce';
$view->base_table = 'commerce_line_item';
$view->human_name = 'Line items';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
dependencies[] = ctools
; Views Handlers
files[] = views/mymodule_handler_handlername.inc
@mglaman
mglaman / node.tpl.php
Created June 4, 2014 01:25
Fancy article tag formatting. Expects "field_tags" to exist and a term reference field.
<?php
// Voila! $submitted now has date and tags.
?>
<p class="submitted"><?php print $submitted; ?></p>
@mglaman
mglaman / gist:bc3143b63ee70a4f6f2c
Created June 5, 2014 14:37
Change a pane style plugin's title
/**
* Implements hook_ctools_plugin_pre_alter().
*/
function module_ctools_plugin_pre_alter(&$plugin, &$info) {
// Rename "Kalacustomize" pane style text label to "Custom Pane Style"
if ($plugin['name'] == 'kalacustomize') {
$plugin['title'] = t('Custom Pane Style');
}
}
@mglaman
mglaman / mymodule.module
Created June 13, 2014 18:32
Adds a field to the Commerce checkout, such as a sales rep.
<?php
/**
* Implements hook_commerce_checkout_pane_info().
*/
function module_commerce_checkout_pane_info() {
$panes['module_salesrep'] = array(
'title' => t('Sales Representative'),
'base' => 'module_salesrep',
@mglaman
mglaman / customize-mediamodal.php
Created June 27, 2014 20:00
Customizes the media edit modal.
<?php
/**
* Implements hook_element_info_alter().
*/
function mymodule_element_info_alter(&$type) {
if ($type['media']) {
$type['media']['#attached']['js'][] = array(
'data' => array(
'media-file-edit' => array(
'modalSize' => array(