Skip to content

Instantly share code, notes, and snippets.

@daggerhart
daggerhart / fast_machine_names.js
Created August 15, 2018 02:03
Fast machine names for Drupal 8 - hacky
(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;
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 September 18, 2019 10:43
Simple script to generate a certificate used for local development on OSX
#!/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 April 1, 2022 20:40
Simple javascript templating function
/**
* Very simple non-hierarchical templating engine
*
* @param name
* @param data
*
* @returns string
*/
@daggerhart
daggerhart / auto_entitylabel_eck_support.php
Last active July 7, 2017 19:21
Drupal 8 - How to add Automatic Entity Label support to ECK (Entity Construction Kit) created bundles
<?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 19:37
Ansible task for Debian/Ubuntu that updates package cache, then as necessary: upgrades, reboots, wait for server to come back up to continue.
# 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
@daggerhart
daggerhart / WordPress Media Library
Last active May 17, 2017 20:56
Description of WP Media Library (In comments)
details in the first comment
@daggerhart
daggerhart / example-drupal-block.php
Last active April 21, 2017 13:00
WordPress Widget API vs Drupal 8 Block Plugin API
<?php
namespace Drupal\example_block\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;
@daggerhart
daggerhart / blog-not-public-admin-notice.php
Created April 12, 2017 22:05
Very simple WordPress plugin that warns a user if their blog can not be indexed by search engines.
<?php
/*
* Plugin Name: Blog not public admin notice
* Description: Because this checkbox costs real people real money
* Version: 1.0.0
* Author: daggerhart
*/
add_action( 'wp_ajax_dismiss_blog_not_public_notice', function(){
update_option('blog_not_public_notice_dismissed', 1);
@daggerhart
daggerhart / acf-allow-ui-to-override-local-on-output.patch
Last active March 15, 2017 05:30
Patch to Advanced Custom Fields 5.5.10 that allows changes to fields in the UI to affect output even if field is "local" JSON or PHP
diff --git a/admin/views/field-group-options.php b/admin/views/field-group-options.php
index ae57dfa..c0871b8 100755
--- a/admin/views/field-group-options.php
+++ b/admin/views/field-group-options.php
@@ -127,6 +127,18 @@ acf_render_field_wrap(array(
));
+// db overrides local
+acf_render_field_wrap(array(