Skip to content

Instantly share code, notes, and snippets.

@daggerhart
daggerhart / AjaxInWebformElement.php
Last active March 1, 2023 00:00
Drupal 9, Webform 6 - custom element w/ ajax in form
<?php
namespace Drupal\ocf_integration_webform\Plugin\WebformElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Element\WebformAjaxElementTrait;
use Drupal\webform\Plugin\WebformElementBase;
use Symfony\Component\HttpFoundation\Request;
/**
@daggerhart
daggerhart / actions\setup-runner\action.yml
Created December 18, 2021 23:08
GitHub Composite Action for deploying to pantheon
name: "Setup Runner"
description: "Provides SSH, PHP, Terminus as a composite action"
inputs:
pantheon_ssh_key:
description: 'Pantheon SSH Private key in the PEM format.'
required: true
ssh_config:
description: 'Contents of the ssh/config file.'
required: true
@daggerhart
daggerhart / MyTokens.php
Created March 13, 2021 17:14
Drupal tokens - hooks vs event_dispatcher
<?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 January 27, 2021 20:58
Drupal 8 views style plugin for a better rest serializer that leverages the Facets module.
<?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
@daggerhart
daggerhart / keybase.md
Created April 7, 2020 19:36
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 March 17, 2020 22:18
Example lando
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 April 21, 2021 07:19
Drupal 8 views style plugin for a better rest serializer.
<?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 March 21, 2019 15:13
Drupal 7 Rules UI improvements
<?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 September 5, 2020 05:23
Drupal 8 file field to media entities simple migration. Does not move files in filesystem, just creates new media entities.
<?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 August 16, 2018 03:40
Drupal 8 get file or image field uri. Get default value if field is empty.
<?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