Skip to content

Instantly share code, notes, and snippets.

@daggerhart
daggerhart / MyTokens.php
Created Mar 13, 2021
Drupal tokens - hooks vs event_dispatcher
View MyTokens.php
<?php
namespace Drupal\mymodule\EventSubscriber;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Utility\Token as TokenService;
use Drupal\core_event_dispatcher\Event\Token\TokensInfoEvent;
use Drupal\core_event_dispatcher\Event\Token\TokensReplacementEvent;
use Drupal\core_event_dispatcher\ValueObject\Token;
use Drupal\core_event_dispatcher\ValueObject\TokenType;
@daggerhart
daggerhart / BetterRestFacetsSerializer.php
Last active Jan 27, 2021
Drupal 8 views style plugin for a better rest serializer that leverages the Facets module.
View BetterRestFacetsSerializer.php
<?php
namespace Drupal\my_module\Plugin\views\style;
use Drupal\facets_rest\Plugin\views\style\FacetsSerializer;
/**
* The style plugin for serialized output formats.
*
* @ingroup views_style_plugins
View keybase.md

Keybase proof

I hereby claim:

  • I am daggerhart on github.
  • I am daggerhart (https://keybase.io/daggerhart) on keybase.
  • I have a public key ASBwqCcP5IkAcu6ev0rhQh5FPl9XHC15g1Qva3B3uZ7Sjgo

To claim this, I am signing this object:

@daggerhart
daggerhart / .lando.yml
Last active Mar 17, 2020
Example lando
View .lando.yml
name: aawp
recipe: wordpress
config:
webroot: wordpress_root
php: '7.3'
xdebug: true
config:
php: .lando/php.ini
#database: .lando/mysql.cnf
#server: .lando/apache.conf
@daggerhart
daggerhart / BetterRestSerializer.php
Last active Apr 21, 2021
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 Sep 5, 2020
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;