Skip to content

Instantly share code, notes, and snippets.

@davereid
davereid / gist:6504748
Last active December 22, 2015 17:18
Drupal.org blacklist user style
@-moz-document domain("drupal.org") {
.submitted a[href="/user/422992"]:after, /*IWasBornToWin*/
.submitted a[href="/user/25027"]:after, /*dgtlmoon*/
.submitted a[href="/user/412207"]:after, /*jddeli*/
.submitted a[href="/user/69670"]:after /*zoon_unit*/
{
content: "BLACKLISTED";
background-color: #000000;
color: #ffffff;
font-weight: bold;
@davereid
davereid / gist:6255133
Last active December 21, 2015 05:09
Disable the media filter from caching.
function mymodule_filter_info_alter(&$info) {
$info['media']['cache'] = FALSE;
}
@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']);
@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: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 / 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: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 / 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: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 / 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