Skip to content

Instantly share code, notes, and snippets.

@davereid
davereid / custom_local.drush.inc
Created July 24, 2012 16:40
Helpful local Drush commands
<?php
/**
* Implements hook_drush_command().
*/
function custom_local_drush_command() {
$items['files-fix-permissions'] = array(
'description' => 'Fix file permissions',
'options' => array(
'owner' => "The name of the user to assign ownership of all files with chown(). Defaults to \$USER.",
@davereid
davereid / drupal-blacklist.user.js
Last active October 6, 2015 22:58
Drupal.org blacklist user script
// ==UserScript==
// @name Drupal.org Blacklist
// @description Helps indicate people on Drupal.org that I have blacklisted from providing help.
// @author Dave Reid
// @version 1.0
// @include http://drupal.org/*
// @include https://drupal.org/*
// @include http://*.drupal.org/*
// @include https://*.drupal.org/*
// ==/UserScript==
@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
@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: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 / 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: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 / 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 / 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 / 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