Skip to content

Instantly share code, notes, and snippets.

Jonathan Daggerhart daggerhart

Block or report user

Report or block daggerhart

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
@daggerhart
daggerhart / BetterRestSerializer.php
Last active Jan 16, 2020
Drupal 8 views style plugin for a better rest serializer.
View BetterRestSerializer.php
<?php
namespace Drupal\my_module\Plugin\views\style;
use Drupal\rest\Plugin\views\style\Serializer;
/**
* The style plugin for serialized output formats.
*
* @ingroup views_style_plugins
@daggerhart
daggerhart / template.php
Created Mar 21, 2019
Drupal 7 Rules UI improvements
View template.php
<?php
/**
* Override the rules ui component row theme function so that we can show much
* more information about each parameter.
*
* - Changed "30" to "200" in the truncate_utf8 function call.
*
* @ingroup themeable
*/
@daggerhart
daggerhart / MODULENAME.install.php
Last active Aug 30, 2018
Drupal 8 file field to media entities simple migration. Does not move files in filesystem, just creates new media entities.
View MODULENAME.install.php
<?php
/**
* Create media entities from existing file fields.
*
* @link https://chromatichq.com/blog/migrating-drupal-file-fields-media-entities-without-migrate-module
*/
function MODULENAME_update_8001() {
// Nodes types that will get media migrated.
$node_types = ['article','event','page','session','sponsor'];
// Map old file fields => new media fields.
@daggerhart
daggerhart / get_file_field_uri.php
Created Aug 16, 2018
Drupal 8 get file or image field uri. Get default value if field is empty.
View get_file_field_uri.php
<?php
use Drupal\file\Entity\File;
/**
* Get the set or default image uri for a file image field (if either exist)
*
* @link https://drupal.stackexchange.com/questions/194176/loading-default-image-from-a-node-field-in-page-html-twig
*
* @param $entity \Drupal\Core\Entity\ContentEntityBase
* @param $fieldName string
@daggerhart
daggerhart / fast_machine_names.js
Created Aug 15, 2018
Fast machine names for Drupal 8 - hacky
View fast_machine_names.js
(function ($, Drupal) {
delete Drupal.behaviors.machineName.transliterate;
Drupal.behaviors.machineName.transliterate = function(str) {
var transliterated = str.replace(' ', '_').replace(/[^\w]+/g,'').toLowerCase();
var deferred = $.Deferred();
var promise = deferred.promise();
deferred.resolve(transliterated);
promise.abort = function() {};
return promise;
View d5-drupalgeddon2.patch
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 2f18c58..93ffef6 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -912,6 +912,7 @@ function _drupal_bootstrap($phase) {
drupal_unset_globals();
// Initialize the configuration
conf_init();
+ drupal_request_sanitizer_sanitize();
break;
@daggerhart
daggerhart / _genCert.sh
Last active Sep 18, 2019
Simple script to generate a certificate used for local development on OSX
View _genCert.sh
#!/bin/bash
read -p 'Domain: ' DOMAIN
openssl req \
-newkey rsa:2048 \
-x509 \
-nodes \
-keyout "$DOMAIN".key \
-new \
@daggerhart
daggerhart / simple-js-template.js
Last active Mar 6, 2018
Simple javascript templating function
View simple-js-template.js
/**
* Very simple non-hierarchical templating engine
*
* @param name
* @param data
*
* @returns string
*/
@daggerhart
daggerhart / auto_entitylabel_eck_support.php
Last active Jul 7, 2017
Drupal 8 - How to add Automatic Entity Label support to ECK (Entity Construction Kit) created bundles
View auto_entitylabel_eck_support.php
<?php
/**
* Implements hook_entity_type_alter().
*/
function example_entity_type_alter(array &$entity_types)
{
foreach ($entity_types as $entity_type) {
if ($entity_type->getProvider() == 'eck' && !is_null($entity_type->getBundleOf())){
$entity_type->setLinkTemplate('auto-label', $entity_type->getLinkTemplate('edit-form') . "/auto-label");
@daggerhart
daggerhart / update-upgrade-reboot-wait.yml
Last active May 24, 2017
Ansible task for Debian/Ubuntu that updates package cache, then as necessary: upgrades, reboots, wait for server to come back up to continue.
View update-upgrade-reboot-wait.yml
# Upgrade Debian/Ubuntu based systems and reboot if necessary.
---
- name: "Update apt-get cache"
apt:
update_cache: yes
- name: "Check if there are packages available to be installed/upgraded"
command: /usr/lib/update-notifier/apt-check --package-names
register: packages
You can’t perform that action at this time.