Skip to content

Instantly share code, notes, and snippets.

Kevin kevinquillen

Block or report user

Report or block kevinquillen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kevinquillen
kevinquillen / ssl.sh
Created Jan 25, 2019
Generate self signed cert for local docker dev with SAN for Chrome (example done on MacOS)
View ssl.sh
openssl req -newkey rsa:2048 -x509 -nodes -keyout cert.key -new -out cert.crt -subj /CN=*.docker.localhost -reqexts SAN -extensions SAN -config <(cat /etc/ssl/openssl.cnf <(printf '[SAN]\nsubjectAltName=DNS:*.docker.localhost')) -sha256 -days 3650
@kevinquillen
kevinquillen / mymodule.module
Created Jan 5, 2019
Custom module for Drupal 7 defining a token for a custom field that stores its data in a `year` column (instead of `value`).
View mymodule.module
<?php
declare(strict_types = 1);
/**
* Implements hook_token_info().
*/
function mymodule_token_info() : array {
$info['tokens']['node']['custom_year'] = array(
'name' => t('Year Field Value'),
@kevinquillen
kevinquillen / prune.sh
Created Jul 24, 2018
Blow away branches that are older than a year.
View prune.sh
#!/bin/sh
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'master$'); do
if [[ "$(git log $branch --since "12 months ago" | wc -l)" -eq 0 ]]; then
# I have to do this because "git log" for me returns current directory contents... not sure why yet.
if [[ ${branch} == *".sh" ]]; then
continue
fi
local_branch_name=$(echo "$branch" | sed 's/remotes\/origin\///')
@kevinquillen
kevinquillen / SurpriseMeController.php
Created Jul 14, 2018
Fetch a random node by type and return it as a JSON response.
View SurpriseMeController.php
<?php
declare(strict_types = 1);
namespace Drupal\harlib_surprise_me\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\node\Entity\Node;
use Symfony\Component\HttpFoundation\JsonResponse;
@kevinquillen
kevinquillen / SurpriseMeController.php
Created Jul 14, 2018
Fetch a random node by type and return it as a JSON response.
View SurpriseMeController.php
<?php
declare(strict_types = 1);
namespace Drupal\harlib_surprise_me\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\node\Entity\Node;
use Symfony\Component\HttpFoundation\JsonResponse;
View ResourceNotFoundController.php
<?php
/**
* Class ResourceNotFoundController.
*/
class ResourceNotFoundController extends ControllerBase {
/**
* Display the Resource Not Found message.
*
@kevinquillen
kevinquillen / OpenNowCheckController.php
Last active Jul 12, 2018
Simple Controller in Drupal via Symfony, returns a JsonResponse cached for 30 seconds.
View OpenNowCheckController.php
<?php
declare(strict_types = 1);
namespace Drupal\harlib_open_now\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Component\Serialization\Json;
@kevinquillen
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
<?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.
*
@kevinquillen
kevinquillen / NodeEntityNormalizer.php
Created Apr 23, 2018
Provides an entity normalizer for certain node types.
View NodeEntityNormalizer.php
<?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
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
<?php
/**
* Implements hook_preprocess_paragraph().
*/
function mytheme_preprocess_paragraph(&$variables) {
$paragraph = $variables['elements']['#paragraph'];
$bundle = $paragraph->getType();
if ($bundle == 'fancy_links') {
You can’t perform that action at this time.