Skip to content

Instantly share code, notes, and snippets.

View bfodeke's full-sized avatar

Bayo Fodeke bfodeke

  • Red Hat
  • United States
View GitHub Profile
/**
* https://www.drupal.org/node/1966736#comment-8792051
*/
<?php
$per_page = 10;
// Initialize the pager
$current_page = pager_default_initialize(count($rows), $per_page);
// Split your list into page sized chunks.
// Filter out array keys that aren't numeric.
$lid_keys = array_filter(array_keys($values), function ($k) {
return is_numeric($k);
});
$lid_values = array_intersect_key($values, array_flip($lid_keys));
@bfodeke
bfodeke / Drupal: Javascript theme function
Created January 18, 2017 16:45
Demonstrates how to create a theme function in javascript.
(function ($) {
// Declare the theme function.
Drupal.theme.prototype.projectTeaser = function(image_url, title, url) {
return '<div class="teaser"><img class="teaser--image" src="' + image_url + '" /><h2 class="teaser--title">' + title + '</h2><a class="teaser--link" href="' + url +'">View Project</a>';
}
Drupal.behaviors.gtpePurchaseOrder = {
attach: function (context, settings) {
// Call the theme function like so. It should return themed markup.
var teaser = Drupal.theme('projectTeaser', 'http://placehold.it/300x300', 'I did this fancy stuff', 'http://npr.org');
/**
* Implements hook_page_alter().
*
* We want to provide more detail to New Relic on the transaction and late in
* the page build seemed like the simplest place.
*/
function MYMODULE_page_alter(&$page) {
if (!extension_loaded('newrelic')) {
return;
}
@bfodeke
bfodeke / Drupal: Implementing Plupload file save
Last active January 18, 2017 20:28
plupload implementation within Drupal with validators.
/**
* PLUPLOAD example form to showcase plupload.
*/
function MYMODULE_some_cool_form() {
$form['file_upload'] = array(
'#type' => 'plupload',
'#title' => t('Upload Files'),
'#required' => TRUE,
'#description' => t('Allowed file extensions: doc docx pdf tif tiff xls xlsx'),
'#upload_validators' => array(
@bfodeke
bfodeke / policy.drush.inc
Created December 20, 2016 19:08 — forked from shrop/policy.drush.inc
Sample Drush policy file
<?php
/**
* @file
* Drush policies to restrict what is allowed for certain drush commands.
*/
/**
* Prevent production databases from being overwritten using drush sql-sync.
*/
<?php
$months = array(
'January' => 31,
'February' => 28,
'March' => 31,
'April' => 30,
'May' => 31,
'June' => 30,
'July' => 31,
'August' => 31,
@bfodeke
bfodeke / Add local .drush folder as a mount to vagrant
Last active July 16, 2021 13:28
Adding local .drush folder as a mount to vagrant drush
// Add a sync folder to sync local drush folder to the vm.
vagrant_synced_folders:
- local_path: ~/.drush
destination: /home/vagrant/.drush
type: nfs
create: true
@bfodeke
bfodeke / ScrollMagic Spin.markdown
Created February 13, 2016 03:17
ScrollMagic Spin
@bfodeke
bfodeke / meta-tags.md
Created December 31, 2015 14:21 — forked from whitingx/meta-tags.md
Complete List of HTML Meta Tags

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta charset='UTF-8'>
<meta name='keywords' content='your, tags'>
<meta name='description' content='150 words'>
<meta name='subject' content='your website's subject'>
<meta name='copyright' content='company name'>