Skip to content

Instantly share code, notes, and snippets.

Pete Barnett petebarnett

Block or report user

Report or block petebarnett

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
petebarnett / FieldTypePluginExample.php
Created Sep 27, 2016
DrupalCon Dumb Storage of Typed Data
View FieldTypePluginExample.php
namespace Drupal\yourmodule\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\zuora\Plugin\DataType\Account;
use Drupal\zuora\TypedData\Definition\AccountDefinition;
View blah.php
$referenced_files = $node->get('your_field')->referencedEntities();
$vars['download_article'] = file_create_url($referenced_files[0]->uri->value);
View test.php
try {
new RecursiveArrayIterator(NULL);
catch(Exception $e) {
print $e->getMessage();
// prints "Passed variable is not an array or object, using empty array instead"
View content_migration.yml
id: the_content
label: Your Content Migration
migration_group: whatever_you_call_this_group
plugin: your_content_source
plugin: entity:your_content_type
plugin: entity:your_custom_entity_type
plugin: default_value
default_value: your_bundle
View DrupalBeforeSend.js
(function($) {
var beforeSend = Drupal.ajax.prototype.beforeSend;
Drupal.ajax.prototype.beforeSend = function(xmlhttprequest, options) {
// Do your thing here...
// And call the original, xmlhttprequest, options);
View gist:90490f07dcbc912bce93
class Test {
function getSomething($something) {
return $something;
$blah = new Test();
View ds_extras_tokens.module
* Implements hook_theme().
function ds_extras_tokens_theme() {
// Declare our own theme hook, to add to the
// theme_hook_suggestions for 'field'
return array(
View gist:9414025
template_preprocess_node(&$vars) {
$field_name = 'your_entityreference_field';
$nid = $vars['content'][$field_name]['#items'][0]['target_id'];
// Add a flag to the referenced node for theming
$vars['content'][$field_name][0]['node'][$nid]['#node']->some_arbitrary_flag = 'some arbitrary value';
You can’t perform that action at this time.