Skip to content

Instantly share code, notes, and snippets.

@davereid
davereid / gist:954384
Created May 3, 2011 22:18
Drupal 7: Entity and bundle select fields with AJAX dependent dropdown
<?php
function entity_bundle_ajax_form() {
$form['entity_type'] = array(
'#type' => 'select',
'#title' => t('Entity type'),
'#options' => array('' => t('- Select one - ')),
'#default_value' => '',
'#ajax' => array(
'callback' => 'entity_bundle_ajax_form_callback',
@davereid
davereid / .gitconfig
Created June 1, 2011 23:44
git branch-diff
[alias]
branch-name = !git for-each-ref --format='%(refname:short)' `git symbolic-ref HEAD`
cd-root = rev-parse --show-cdup
branch-diff = !git format-patch --stdout $1 > `git cd-root``git branch-name`.patch
@davereid
davereid / helloworld.info
Created August 5, 2011 22:08
Drupal Hello World
name = Hello World
description = "The most basic exercise known to programmers, the good old Hello world."
core = 7.x
@davereid
davereid / media_views.info
Created November 1, 2011 19:07
Temporary media views integration for 1.x
name = Media browser views
description = Provides views integration for the media browser.
package = Media
core = 7.x
dependencies[] = media
dependencies[] = views
files[] = views_handler_field_file_link_media_browser.inc
@davereid
davereid / gist:1365457
Created November 14, 2011 22:43
file_get_uri_from_url()
<?php
function file_get_uri_from_url($url, $load_file = TRUE) {
$base_paths = &drupal_static(__FUNCTION__);
if (!isset($base_paths)) {
$base_paths = array();
foreach (file_get_stream_wrappers() as $scheme => $stream_wrapper) {
$class = file_stream_wrapper_get_class($scheme);
if (class_exists($class) && method_exists($class, 'getExternalUrl')) {
@davereid
davereid / gist:1520145
Created December 26, 2011 00:33
Allowing node template in your module directory
/**
* Implements hook_theme_registry_alter().
*/
function mymodule_theme_registry_alter(&$info) {
// Inject our module into the node theme registry as being an available theme
// path so that we can override the node template for our content type.
array_splice($info['node']['theme paths'], 1, 0, array(drupal_get_path('module', 'mymodule')));
}
@davereid
davereid / custom.admin_menu.inc
Last active September 29, 2015 07:18
Useful D7 custom functions
<?php
/**
* @file
* Administration menu integration for the custom module.
*/
/**
* Implements hook_admin_menu_cache_info().
*/
@davereid
davereid / gist:3012194
Created June 28, 2012 16:05
Workaround for embedding non-image media in WYSIWYG
<?php
/**
* Implements hook_media_token_to_markup_alter().
*
* Allow non-image files to be embedded in the WYSIWYG by converting the
* 'preview' markup to be shown in the WYSIWYG to an image preview of the file.
*/
function custom_media_token_to_markup_alter(&$element, $tag_info, $settings) {
if (!empty($settings['wysiwyg']) && $tag_info['file']->type != 'image') {
@davereid
davereid / gist:3012246
Created June 28, 2012 16:16
Disable deprecated media library tab
<?php
/**
* Implements hook_media_browser_plugin_info_alter().
*/
function custom_media_browser_plugin_info_alter(&$info) {
unset($info['library']);
}
/**
@davereid
davereid / gist:3020238
Created June 29, 2012 19:48
media_url_filter
<?php
// This code was removed from Media module as it was no longer used and does not work.
// Removed via http://drupal.org/node/1268268
/**
* Filter callback for media url filter.
* @TODO: There are currently problems with this. For instance, if a file is
* to be loaded from a remote location here, it will be recreated multiple
* times, each time this filter is called. If we want to continue supporting