Skip to content

Instantly share code, notes, and snippets.

View JeffTomlinson's full-sized avatar

Jeff Tomlinson JeffTomlinson

View GitHub Profile
@JeffTomlinson
JeffTomlinson / example_entity_form_extract_element.php
Last active August 29, 2015 14:26
Extract Drupal 7 form API elements from and existing entity form
/**
* Extracts a form API element from and existing entity form.
*
* @param string $field_name
* The field name of the element to extract.
* @param string $form_id
* The form ID of the entity form from which to extract the element.
* @param string $entity_type
* The entity type fo the entity form.
* @param string $bundle_name
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;
}
@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) {
@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 / 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 / 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 / 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', '=')
/**
* 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 / 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) {
@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.