Skip to content

Instantly share code, notes, and snippets.

View JeffTomlinson's full-sized avatar

Jeff Tomlinson JeffTomlinson

View GitHub Profile
@JeffTomlinson
JeffTomlinson / migration.d6_node.yml
Created January 23, 2019 02:01
Drupal 6 to 8 date range migration
process:
field_destination_daterange:
plugin: iterator
source: field_source_daterange
process:
value:
plugin: format_date
from_format: 'Y-m-d\TH:i:s'
to_format: 'Y-m-d'
source: value
@JeffTomlinson
JeffTomlinson / ExamplePlugin.php
Last active January 18, 2021 20:23
Drupal 8 Logger Dependency Injection
<?php
namespace Drupal\example\Plugin\ExamplePlugin;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Logger\LoggerChannel;
/**
* Example plugin.
@JeffTomlinson
JeffTomlinson / parse_multiline_pipe_delimited_string.php
Last active November 17, 2018 02:22
Parse multiline pipe delimited strings
/**
* Extracts an array of key/value pairs from the input string.
*
* @param string $string
* The input string to extract values from.
*
* @return array
* An array of key/value pairs.
*/
function parse_multiline_pipe_delimited_string($string) {
/**
* Explanation of what this update does.
*/
function example_update_7100(&$sandbox) {
$limit = 1;
if (!isset($sandbox['processed'])) {
$nids = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', 'page', '=')
@JeffTomlinson
JeffTomlinson / example.install
Created July 6, 2017 16:50
Drupal 7 Batch Update Hook
/**
* Explanation of what this update does.
*/
function example_update_7100(&$sandbox) {
$limit = 1;
if (!isset($sandbox['processed'])) {
$nids = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', 'page', '=')
@JeffTomlinson
JeffTomlinson / my_module.php
Last active April 22, 2017 21:59
Drupal: Set module implementation weight after that of another module
<?php
/**
* Implements hook_module_implements_alter().
*/
function my_module_module_implements_alter(&$implementations, $hook) {
if ($hook === 'form_alter') {
// Implement after simplesamlphp_auth.
if (isset($implementations['simplesamlphp_auth'])) {
$my_module = ['my_module' => $implementations['my_module']];
@JeffTomlinson
JeffTomlinson / MyService.php
Last active August 7, 2024 11:28
Drupal 8 Configuration Dependency Injection
<?php
namespace Drupal\my_module\Services;
use Drupal\Core\Config\ConfigFactory;
/**
* Class MyService.
*
* @package Drupal\my_module\Services
@JeffTomlinson
JeffTomlinson / MyService.php
Last active December 22, 2021 07:49
Drupal 8 Logger Dependency Injection
<?php
namespace Drupal\my_module\Services;
use Drupal\Core\Logger\LoggerChannelFactory;
/**
* Class MyService.
*
* @package Drupal\my_module\Services
@JeffTomlinson
JeffTomlinson / jsonObjToPhpArray.js
Last active September 9, 2015 20:07
Convert a JSON object to a string representation of a PHP array.
var _ = require('lodash');
/**
* Renders input value as a string representation of a php variable value.
*
* @param {int|boolean|string} value - The value to render.
*
* @returns {string} A string representing a php variable value.
*/
renderPhpVar = function(value) {
Template.breweryForm.helpers({
canCreateBrewery: function () {
// This is the part that seems weird.
var clientResult = Meteor.apply('canCreateBrewery', [], {returnStubValue: true}, function(err, serverResult) {
// If this is indeed the way this should be done, I'd like to
// update the template when the server result is returned.
});
return clientResult;
}