Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / gist:3173153
Last active October 7, 2015 13:38
drupal_deliver_minimal_html_page
<?php
function drupal_deliver_minimal_html_page($page_callback_result) {
if (is_int($page_callback_result)) {
return drupal_deliver_html_page($page_callback_result);
}
// Emit the correct charset HTTP header, but not if the page callback
// result is NULL, since that likely indicates that it printed something
// in which case, no further headers may be sent, and not if code running
@davereid
davereid / gist:3382971
Created August 17, 2012 21:43
Changing layout of panel on the fly
/**
* Implements hook_panels_pre_render().
*/
function custom_panels_pre_render($display, $renderer) {
// To switch a panel's layout on the fly, you need to not only set
// the display's layout, but also swap out the layout plugin in the
// renderer object.
ctools_include('plugins', 'panels');
if ($plugin = panels_get_layout($layout)) {
$display->layout = $layout;
@davereid
davereid / custom.module
Created December 5, 2012 20:06
Adding sorts for long text fields in Views
<?php
/**
* Implements hook_field_views_data_alter().
*
* Views disables sorting on any field columns that have a schema type of 'text'
* even though it's valid to sort on those fields. Force those field columns to
* have a sort available in Views.
*
* CAUTION: Sorting on these fields may cause performance issues with queries.
@davereid
davereid / gist:4639015
Last active December 11, 2015 18:08
Entity operation automation
<?php
function entity_get_operation_links($entity_type, $entity, $base_path = NULL) {
$build = array(
'#theme' => 'links__operations__' . $entity_type,
'#links' => array(),
'#attributes' => array('class' => array('links inline')),
);
list($entity_id) = entity_extract_ids($entity_type, $entity);
@davereid
davereid / settings.local.php
Created February 25, 2013 23:05
settings.local.php for development
<?php
// Twig development settings.
$settings['twig_debug'] = TRUE;
$settings['twig_auto_reload'] = TRUE;
$settings['twig_cache'] = FALSE;
// Use FileStorage.
// @see http://drupal.org/node/1908440
// @see http://drupal.org/node/1899842
@davereid
davereid / gist:5408617
Last active December 16, 2015 08:49
Removing instance settings on uninstall
<?php
/**
* Implements hook_uninstall().
*/
function mymodule_uninstall() {
$fields = field_read_fields(array('module' => 'mymodule'));
$instances = field_read_instances(array('field_name' => array_keys($fields)));
foreach ($instances as $instance) {
if (isset($instance['settings']['my_added_setting'])) {
@davereid
davereid / gist:5414416
Created April 18, 2013 17:06
Custom field default value functions
<?php
/**
* Custom field default value function for entity reference fields.
*/
function entityreference_get_default_handler_value($entity_type, $entity, $field, $instance, $langcode) {
if (!isset($instance['settings']['default_handler']) || !isset($instance['settings']['default_handler_settings'])) {
return array();
}
@davereid
davereid / gist:5799266
Created June 17, 2013 18:48
inline_entity_form widget tweaks
<?php
/**
* Implements hook_field_widget_WIDGET_TYPE_form_alter().
*
* Make some visual tweaks to the inline entity form and it's subforms.
*/
function custom_field_widget_inline_entity_form_form_alter(&$element, &$form_state, $context) {
$info = entity_get_info($element['entities']['#entity_type']);