Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin kevinquillen

View GitHub Profile
@kevinquillen
kevinquillen / FeatureContext.php
Last active Jul 22, 2020
A Behat definition that will instruct the client to press a vertical tab, useful for forms leveraging Field Group in Drupal (Shiny admin theme).
View FeatureContext.php
/**
* @When I press the :vertical_tab vertical tab
* @param $vertical_tab
*/
public function iPressTheVerticalTab($vertical_tab) {
$this->getSession()->getDriver()->click('//*[contains(@class, "node-form")]/div/div[contains(@class, "vertical-tabs")]/ul/*/a/strong[text()="' . $vertical_tab . '"]');
}
@kevinquillen
kevinquillen / AddUser.php
Last active Jan 7, 2020
Example Symfony 5 maker command to create a user entity from command line.
View AddUser.php
<?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 / README.md
Created Jun 2, 2013
Reddit Widget for Dashing
View README.md

Preview

Description

Took a little inspiration from the News widget to construct this Reddit widget. Simply add the subreddit .json feed URLs that you want to the top of the reddit.rb job script, and the widget will cycle through each one, showing top posts, their score, and comment count. You can also set the maxcount higher or lower, the default is 5 posts.

##Usage

@kevinquillen
kevinquillen / migrate_plus.migration.redirects.yml
Created Dec 8, 2019
Example redirect migration from XML source in Drupal 8.
View migrate_plus.migration.redirects.yml
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 / gist:4235124
Created Dec 7, 2012
Adding menu names to the ul menus in Drupal 7
View gist:4235124
function themename_menu_link(&$variables) {
$element = $variables['element'];
$sub_menu = '';
$element['#attributes']['data-menu-parent'] = $element['#original_link']['menu_name'] . '-' . $element['#original_link']['depth'];
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
@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 / SearchResults.php
Created Sep 6, 2016
Example of a Controller using SearchAPI to generate a results page (without Views).
View SearchResults.php
<?php
namespace Drupal\velirsearch\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\velirsearch\Service\PagerService;
class SearchResults extends ControllerBase {
@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 / replaceFieldTextTo.sql
Created Jul 10, 2017
Does a mass find+replace on Drupal field_*_value fields within tables - useful for when you need to replace a string in a huge amount of tables.
View replaceFieldTextTo.sql
CREATE PROCEDURE replaceFieldTextTo (IN v_string_from VARCHAR(255), IN v_string_to VARCHAR(255))
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE table_name_value VARCHAR(64);
DECLARE column_name_value VARCHAR(64);
DECLARE cursor_fields CURSOR FOR SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE 'field_%_value';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cursor_fields;
@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\///')