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
@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.
*/
@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(
/**
* 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: 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');
// 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));
/**
* 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.
@bfodeke
bfodeke / Drupal: Field and Instance Export
Last active May 11, 2017 14:30
After creating a field in the UI, get the export code to put in custom module.
<?php
// https://steindom.com/articles/exporting-and-creating-field-definitions-drupal-7
$entity_type = 'node';
$field_name = 'field_name';
$bundle_name = 'content_type';
$info_config = field_info_field($field_name);
$info_instance = field_info_instance($entity_type, $field_name, $bundle_name);
unset($info_config['id']);
/**
* Implements hook_page_alter().
*/
function mymodule_page_alter(&$page) {
if (!extension_loaded('newrelic')) {
return;
}
$name = NULL;
@bfodeke
bfodeke / Drupal: Create redirect
Created June 16, 2017 12:16
Create a redirect to a path using the redirect module.
// Apply redirect from old content to new content.
$old_alias = 'some/old/path';
$new_alias = 'node/' . $node->nid;
$redirect = new stdClass();
redirect_object_prepare($redirect);
$redirect->source = $old_alias;
$redirect->redirect = $new_alias;
redirect_save($redirect);
@bfodeke
bfodeke / mymodule.css
Created July 26, 2017 14:33 — forked from AlexSkrypnyk/mymodule.css
Drupal 'add more' and 'remove single' AJAX buttons on multi value custom field using FormAPI
input.form-submit.button-small {
padding: 4px 8px;
font-weight: bold;
}
.container-inline input.form-submit.button-small + .ajax-progress.ajax-progress-throbber .throbber {
position: absolute;
left: 19px;
margin-top: 7px;
}