Skip to content

Instantly share code, notes, and snippets.

@rjpeter2
rjpeter2 / gist:6356839
Last active December 21, 2015 19:49
Programmatically delete fields and content types
<?php
// Array of content types.
$types = array('page', 'article');
foreach ($types as $type) {
// Gather all the example content that might have been created while this
// module was enabled. Simple selects still use db_query().
// api.drupal.org/api/function/db_query/7
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
$result = db_query($sql, array(':type' => $type));
@rjpeter2
rjpeter2 / gist:5322827
Last active December 15, 2015 20:59
Have Drupal find your modules tpl overrides.
<?php
// Create a variable to store the path to this module
define('MY_MODULE_PATH', drupal_get_path('module', 'pricing_calculator'));
/**
* Implements hook_theme_registry_alter().
*
* Makes Drupal find our page template file.
* Found this at: http://drupal.org/node/715160
@rjpeter2
rjpeter2 / gist:4739764
Created February 8, 2013 15:38
SASS for Responsive Youtube Video
.parent-of-iframe {
float: left;
clear: left;
position: relative;
margin: 1.5em 0;
padding-bottom: 56.25%; /* 16/9 ratio */
padding-top: 30px; /* IE6 workaround */
width: 100%;
height: 0;
overflow: hidden;
@rjpeter2
rjpeter2 / gist:3406766
Created August 20, 2012 19:05
Show a teaser (or other view mode) on content the user does not have access to.
<?php
/**
* Implements hook_page_delivery_callback_alter().
*
* The idea for this came from this page:
* http://drupal.stackexchange.com/questions/327/how-can-a-module-detect-when-drupal-is-outputting-the-access-denied-page
*/
function custom_page_delivery_callback_alter(&$callback) {
if ($callback == 'drupal_deliver_html_page') {
@rjpeter2
rjpeter2 / gist:3315485
Created August 10, 2012 16:45
Overriding theme functions in a custom module.
<?php
/* Normally you would override theme function in your theme! However, if you want to
override something in the admin area where you are using an admin theme, you can do
the following */
/**
* Implements hook_theme_registry_alter().
*/
function custom_theme_registry_alter(&$theme_registry) {
if (isset($theme_registry['file_link'])) {
@rjpeter2
rjpeter2 / gist:3307956
Created August 9, 2012 20:54
Field Formatter for replacing empty field with another.
<?php
/**
* Implements hook_field_formatter_info().
*/
function custom_field_formatter_info() {
$formatters = array();
$formatters['custom_event_time'] = array(
'label' => t('CUSTOM: Event Time'),
'description' => t('Displays this field normally if it has a value, if empty, it displays the time from field_event_date.'),
'field types' => array('text'),