Skip to content

Instantly share code, notes, and snippets.

@kevinchampion
kevinchampion / vote_totals.php
Created June 6, 2013 22:45
Vote total for all characters
if (module_exists('content_vote')) {
$votes = content_vote_retrieve_vote_totals($node->nid);
}
if (module_exists('massrel_voting')) {
$tweets = massrel_voting_retrieve_vote_totals($node->nid);
/**
* Implements hook_theme().
*/
function content_vote_theme($existing, $type, $theme, $path) {
return array(
// VOTE BUTTONS
'content_vote' => array(
'variables' => array(
'gameid' => NULL,
/**
* Implements hook_theme().
*/
function content_vote_theme($existing, $type, $theme, $path) {
return array(
// VOTE BUTTONS
'content_vote' => array(
'variables' => array(
'gameid' => NULL,
@kevinchampion
kevinchampion / lang.php
Last active December 16, 2015 16:09
language handling best practice
/**
* Link field has issue with rendering the <front> option. Lets give it a bit
* of help
* @param $variables preprocess variables
* @param $hook
*/
function openedu_linkblock_preprocess_field(&$vars, $hook) {
global $language;
$lang = $language->language;
@kevinchampion
kevinchampion / isu_panel_layouts.module
Created April 16, 2013 22:41
Radioactivity with Panels contexts
/**
* Implements hook_ctools_render_alter().
*/
function isu_panel_layouts_ctools_render_alter(&$info, &$page, &$context) {
if (!empty($context['contexts'])) {
// I don't know why this is necessary, but just looping over the contexts
// array is throwing an unknown error.
$context_keys = array_keys($context['contexts']);
@kevinchampion
kevinchampion / ckeditor.config.js
Created April 10, 2013 14:59
Ckeditor modification
CKEDITOR.on( 'dialogDefinition', function( ev ) {
// Take the dialog name and its definition from the event data.
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
// Check if the definition is from the dialog we're
// interested in (the 'link' dialog).
if ( dialogName == 'link' ) {
@kevinchampion
kevinchampion / ckeditor.api.php
Last active December 14, 2015 20:40
ckeditor error
/**
* Hook to register the CKEditor plugin - it would appear in the plugins list on the profile setting page.
*/
function hook_ckeditor_plugin() {
return array(
'plugin_name' => array(
// Name of the plugin used to write it.
'name' => 'plugin_name',
// Description of the plugin - it would be displayed in the plugins management section of profile settings.
'desc' => t('Plugin description'),
@kevinchampion
kevinchampion / module_pattern.js
Last active December 12, 2015 12:29
Javascript namespacing pattern
/**
* This pattern allows you to manually return the functions you want to be public,
* thus allowing for private functions.
*/
var Mcard = (function() {
/**
* Helper to update form and results based on query as retrieved from a url
* change.
@kevinchampion
kevinchampion / mcard_menu.php
Last active December 11, 2015 17:48
Mcard autocomplete
/**
* Implementation of hook_menu().
*/
function mcard_menu() {
$items['admin/settings/mcard'] = array(
'title' => 'Mcard',
'description' => 'Adjust Mcard discount settings',
'page callback' => 'drupal_get_form',
'page arguments' => array( 'mcard_discount_settings' ),
@kevinchampion
kevinchampion / hook_cron.php
Last active December 10, 2015 14:18
Cron consolidate queries
$last_month = date("n", mktime(0, 0, 0, date("n")-1, 1, date("Y")));
$last_month_year = date("Y", mktime(0, 0, 0, date("n")-1, 1, date("Y")));
// Query for all revenue sources who have an active unit and don't have a
// sales tax report for last month. The resulting revenue sources all need
// new tax reports created for them for last month.
$query = "SELECT
n.nid as nid
FROM {node} n
INNER JOIN {content_field_revenue_unit_ref} r ON r.nid = n.nid