Skip to content

Instantly share code, notes, and snippets.

View kevinquillen's full-sized avatar

Kevin kevinquillen

View GitHub Profile
@kevinquillen
kevinquillen / gist:d32dd7bb5ce1f288452241b9205312aa
Created February 20, 2024 20:03
Forbid all Wordpress traffic on Drupal sites with htaccess, any URI beginning with "wp-".
# Block common Wordpress paths.
RewriteCond %{REQUEST_URI} ^/wp-(.*)? [NC]
RewriteRule ^ - [F]
@kevinquillen
kevinquillen / AddUser.php
Last active January 7, 2020 16:34
Example Symfony 5 maker command to create a user entity from command line.
<?php
declare(strict_types=1);
namespace App\Maker;
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
use Symfony\Component\Console\Command\Command;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
@kevinquillen
kevinquillen / migrate_plus.migration.redirects.yml
Created December 8, 2019 22:45
Example redirect migration from XML source in Drupal 8.
id: redirects
label: Old article paths.
migration_group: content
source:
plugin: url
data_fetcher_plugin: http
data_parser_plugin: simple_xml
urls: http://kevinquillen.com/atom.xml
namespaces:
atom: http://www.w3.org/2005/Atom
@kevinquillen
kevinquillen / ssl.sh
Created January 25, 2019 15:36
Generate self signed cert for local docker dev with SAN for Chrome (example done on MacOS)
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 January 5, 2019 15:25
Custom module for Drupal 7 defining a token for a custom field that stores its data in a `year` column (instead of `value`).
<?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 July 24, 2018 14:06
Blow away branches that are older than a year.
#!/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 July 14, 2018 13:35
Fetch a random node by type and return it as a JSON response.
<?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 July 14, 2018 13:35
Fetch a random node by type and return it as a JSON response.
<?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;
<?php
/**
* Class ResourceNotFoundController.
*/
class ResourceNotFoundController extends ControllerBase {
/**
* Display the Resource Not Found message.
*
@kevinquillen
kevinquillen / OpenNowCheckController.php
Last active July 12, 2018 19:15
Simple Controller in Drupal via Symfony, returns a JsonResponse cached for 30 seconds.
<?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;