Skip to content

Instantly share code, notes, and snippets.


Kevin kevinquillen

View GitHub Profile
kevinquillen /
Created Jan 30, 2018
Detect branch being built with TravisCI and and use different gulp parameters depending on where the deployment is going.
#!/usr/bin/env bash
branch=`echo ${TRAVIS_BRANCH}`;
if [ $branch = "master" ]; then
echo "Building assets for production.";
gulp build --env production;
echo "Building assets for development.";
gulp build --no-watch;
kevinquillen / EmailMatcher.php
Created Jul 28, 2017
Utility class with a helper method that lets me check if the incoming email address input by the user matches a given domain I am verifying against. See the corresponding test:
View EmailMatcher.php
namespace Drupal\iana_netforum_auth\Utility;
* Class EmailMatcher.
* @package Drupal\iana_netforum_auth\Utility
class EmailMatcher {
kevinquillen / EmailMatcherTest.php
Last active Jan 30, 2018
Example PHPUnit test with UnitTestCase testing a method of a utility class
View EmailMatcherTest.php
namespace Drupal\Tests\iana_netforum_auth\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\iana_netforum_auth\Utility\EmailMatcher;
* Test email matching component class.
kevinquillen / SearchController.php
Last active Jan 30, 2018
Creating a route that makes a call from the server to an external service which is firewalled, with data sent back to the caller (like a ReactJS component)
View SearchController.php
namespace Drupal\harlib_search\Controller;
use Drupal\Core\Controller\ControllerBase;
use GuzzleHttp\Client;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use GuzzleHttp\Exception\RequestException;
kevinquillen / mymodule.php
Created Mar 7, 2018
How to update a field storage length in hook_install (or hook_update). Note this does not cover more difficult things, like changing storage type altogether.
View mymodule.php
use Drupal\Core\Database\Database;
* Implements hook_install().
function mymodule_install() {
$connection = Database::getConnection('default');
kevinquillen / example.go
Last active Mar 11, 2018
Just learning a little bit about Go.. using http client to get a response and look at the data.
View example.go
package main
import "fmt"
import "net/http"
import "io/ioutil"
import "time"
import "log"
func main() {
var url = "[redacted]/api/v1/room"
kevinquillen / mytheme.theme
Last active Apr 19, 2018
Various ways of adding classes to anchors, as well as title markup within that anchor, from hook_preprocess_field in Drupal 8. These are all link fields, which do not have a base twig to modify the output of the a tag.
View mytheme.theme
* Implements hook_preprocess_field().
function mytheme_preprocess_field(&$variables) {
if ($variables['element']['#entity_type'] == 'paragraph' && $variables['field_name'] == 'field_reference_link') {
foreach ($variables['items'] as $key => $item) {
$variables['items'][$key]['content']['#options']['attributes']['class'][] = 'hl__link-tag';
kevinquillen / mytheme.theme.php
Last active Apr 19, 2018
Another theme example - preprocessing fields on a paragraph. Formats links with SVG icons next to the title value. FormattableMarkup creates a markup for each link which is being passed as a new variable into the template. This could also be done via hook_preprocess_field, but demonstrates that you can do this from other preprocess hooks.
View mytheme.theme.php
* Implements hook_preprocess_paragraph().
function mytheme_preprocess_paragraph(&$variables) {
$paragraph = $variables['elements']['#paragraph'];
$bundle = $paragraph->getType();
if ($bundle == 'fancy_links') {
kevinquillen / NodeEntityNormalizer.php
Created Apr 23, 2018
Provides an entity normalizer for certain node types.
View NodeEntityNormalizer.php
declare(strict_types = 1);
namespace Drupal\harlib_restful_normalizer\Normalizer;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Url;
use Drupal\harlib_libcal_api\LibCalApi;
use Drupal\image\Entity\ImageStyle;
kevinquillen / RandomEntityFieldFormatter.php
Created Jun 25, 2018
This field formatter can be used on entity reference fields to select a random entity from the list to render. Note that the more items you have, the better the 'random' pick will seem. Also note that this will only fire once per cache write, then again on cache clear.
View RandomEntityFieldFormatter.php
namespace Drupal\harlib_random_entity_display\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter;
* Plugin implementation of the 'random_entity_field_formatter' formatter.