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 / FeatureContext.php
Last active July 22, 2020 18:47
A Behat definition that will instruct the client to press a vertical tab, useful for forms leveraging Field Group in Drupal (Shiny admin theme).
/**
* @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 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 / README.md
Created June 2, 2013 21:25
Reddit Widget for Dashing

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 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 / gist:4235124
Created December 7, 2012 18:02
Adding menu names to the ul menus in Drupal 7
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 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 / SearchResults.php
Created September 6, 2016 16:58
Example of a Controller using SearchAPI to generate a results page (without Views).
<?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 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 / replaceFieldTextTo.sql
Created July 10, 2017 17:38
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.
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;