Skip to content

Instantly share code, notes, and snippets.

View jameswilson's full-sized avatar

James Wilson jameswilson

View GitHub Profile
@jameswilson
jameswilson / pager.tpl.php
Last active August 19, 2020 15:42
Drupal 7 Accessible Pager (Backport from Drupal 8)
<?php
// Place this file your theme's "templates" folder.
/**
* @file
* Theme override to display a pager.
*
* This is a backport of pager.html.twig from Drupal 8 to Drupal 7, which add
* accessibility support for WCAG 2.0 section 2.4.9.
*
@jameswilson
jameswilson / update-module-location.sh
Last active August 29, 2015 14:13
Update module locations in Drupal 7 from sites/all/modules/contrib to profiles/distroname/modules/contrib
#!/usr/bin/php
<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
db_query("UPDATE {system} SET filename = replace(filename, 'sites/all/modules/contrib', 'profiles/distroname/modules/contrib');")->execute();
@jameswilson
jameswilson / node_counts_by_type.mysql
Created November 21, 2014 18:03
Drupal Node Count by Type
# Tested with Drupal 6 and Drupal 7.
SELECT
COUNT(node.nid) AS count,
node_type.type AS type
FROM
node_type
LEFT JOIN
node ON node.type = node_type.type
GROUP BY
node.type
@jameswilson
jameswilson / remove_body_field.php
Created November 12, 2014 14:38
Remove the body field from a specific content type.
/**
* Remove the instance of the body field from my_content_type
*/
function my_feature_update_7000() {
$instance = field_info_instance('node', 'body', 'my_content_type');
field_delete_instance($instance);
}
@jameswilson
jameswilson / pull-hero-region-layout.tpl.php
Last active August 29, 2015 14:06
Move content from a panel pane region into a Drupal theme region using drupal_add_region_content(). This requires a small core patch https://www.drupal.org/node/713462.
<?php
// path/to/mytheme/plugins/layouts/pull_hero_region_layout/pull_hero_region_layout.tpl.php
/**
* @file
* Template for the "pull_hero_region_layout" layout.
*
*
* Variables:
* - $has_content: Boolean TRUE if any regions have content to display.
* - $attributes: A list of attributes for the layout container.
// Animated throbber
html.js .form-autocomplete {
background-image: image-url('svg/throbber-inactive.svg');
background-position: 95% center;
background-position: -webkit-calc(100% - 5px) center;
background-position: calc(100% - 5px) center;
background-repeat: no-repeat;
}
html.js .throbbing {
@jameswilson
jameswilson / localized_placeholder_node_and_menu_item.php
Created August 25, 2014 23:55
Programmatically create a placeholder node with translations and localized main menu links.
<?php
// The following code snippet is used to add a placeholder page and companion
// localized menu items to a site with i18n_menu and entity_translation enabled.
/**
* Create an About page.
*/
function mymodule_create_about_page() {
// Config data.
@jameswilson
jameswilson / mytheme_template.php
Created August 9, 2014 12:18
Remove duplicate stylesheets for RTL themes that use _directional.scss
<?php
/**
* Implements hook_css_alter().
*/
function mytheme_css_alter(&$css) {
global $language;
// If the current language is RTL, find and remove CSS files from this
// theme that have the RTL overrides. Drupal's RTL methodology adds files
@jameswilson
jameswilson / better_bean_classes.php
Created August 7, 2014 21:09
Cleanup bean classes.
<?php
/**
* Implements hook_preprocess_block().
*/
function mymodule_preprocess_entity(&$variables) {
// modify the classes on bean entities.
if ($variables['entity_type'] == 'bean') {
$variables['classes_array'] = array(
drupal_html_class($variables['bean']->type),
<?php
/**
* @file
* html_in_title.features.filter.inc
*/
/**
* Implements hook_filter_default_formats().
*/
function html_in_title_filter_default_formats() {