Skip to content

Instantly share code, notes, and snippets.

@grayside
grayside / BackReferenceFinder.php
Created January 27, 2017 23:14
Finding Backreferences and relevant backreferencing fields.
<?php
namespace Drupal\back_reference;
use Drupal\field\Entity\FieldConfig;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Entity\EntityFieldManager;
/**
@grayside
grayside / Dockerfile-yeoman
Last active February 13, 2017 07:32
Dockerfile for running Phase2 Yeoman generators and capturing the output via a volume mount.
FROM node:4-alpine
ENV YO_P2_VERSION 2.2.0
ENV PATTERN_LAB_STARTER_VERSION 2.0.0
ENV GADGET_VERSION 1.0.0-rc1
ENV P2_ENV_VERSION 1.2.0
RUN node -v
RUN npm -v
RUN echo "Yeoman Doctor will warn about our npm version being outdated. It is expected and OK."
@grayside
grayside / identifying-things.md
Created October 20, 2016 04:39
Identifying a plugin in Drupal 8

A co-worker recently asked me if the following is a good way to identify objects in Drupal 8:

get_class($object) == 'Drupal\Namespace\Thinger\ThingObjectService'

That totally works. It's just not very durable.

In Drupal 8, there is a built-in notion that almost anything might be swapped out for a different behavior. Thinger Service is known to be powered by a given class, but that class can be changed. Plugin X is defined as associated with a given class by annotations and whatnot, but those, too, can have their class changed. This means any code that hardwires a specific class has a slight amount of brittleness.

@grayside
grayside / InboundWebhookSubscriber.php
Created September 2, 2016 17:48
Webhook Migrate Non-blocking Subscriber Implementation
<?php
namespace Drupal\webhook_migrate\EventSubscriber;
use Drupal\webhook_migrate\MigrateRunner;
use Drupal\webhooks\EventSubscriber\NonBlockingSubscriberBase;
use Drupal\webhooks\Webhook;
use Drupal\webhooks\WebhookRelayQueue;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\Core\Lock\LockBackendInterface;
@grayside
grayside / CONTRIBUTING.md
Created May 21, 2015 22:26
Default development practices & processes documentation to be included in new Drupal project repositories.

This extension to the README is necessary for all developers working on the {projectName} codebase.

Build Process

As described in the README, the many steps of assembling, installing, and managing the site have been combined into a few simple commands using Grunt Drupal Tasks.

You can see a list of all available actions by running grunt help.

{
"emptyImage": "http://crisis.rwdev.org/img/overview-map.jpg",
"items": {
"type": "request",
"source": "reliefweb",
"method": "POST",
"path": "v1/reports?limit=50&fields[include][0]=date&fields[include][1]=headline&fields[include][2]=primary_country&fields[include][3]=url",
"payload": {
"facets": [
{
{
"filters": [
{
"id": "situation-reports",
"title": "Situation reports by UN agencies",
"location": "http://reliefweb.int/updates?advanced-search=(C226.C122)_(F10)_(ST272)#content",
"data": {
"type": "request",
"source": "reliefweb",
"method": "POST",
{
"title": "Crisis Overview",
"dataSource": "Data Sources <cite><a href=\"http://reliefweb.int/sites/reliefweb.int/files/resources/2015_SRP_Syria_\" target=\"_top\">Syria IDPs</a>, <a href=\"http://reliefweb.int/report/iraq/fast-track-priorities-iraq-february-jun\" target=\"_top\">Iraq IDPs</a>, <a href=\"https://data.hdx.rwlabs.org/dataset/unhcr-refugee-pop-stats\" target=\"_top\">Syria Refugees - UNHCR via HDX</a>, <a href=\"http://www.unhcr.org/pages/49e486426.html#\" target=\"_top\">Iraq Refugees</a></cite>",
"map": {
"src": "http://crisis.rwdev.org/img/overview-map.jpg",
"alt": "Syria/Iraq"
},
"content": {
"syria": {
"title": "Syria",
{
"fundingDocumentURL": "http://reliefweb.int/updates?advanced-search=(C226.C122)_(F4)_!(S1242)_!(S1741)_!(S1255)_!(PC254)_!(S4304)#content",
"dataSources": [
{
"dataItemTitle": "Iraq Strategic Response Plan 2014-2015",
"dataSourceURL": "http://fts.unocha.org/reports/daily/OCHA_R32sum_A983.PDF",
"clusters": {
"type": "request",
"source": "fts",
"path": "v1/cluster/appeal/983.json",