Skip to content

Instantly share code, notes, and snippets.

@schnippy
schnippy / Drupal7RandomNode.md
Last active September 23, 2019 18:31
Drupal 7: Create menu_hook to load random node of approved content types for more efficient debugging and testing

Drupal 7: Create menu_hook to load random node by type

On many projects, I often have a need to be able to see a random node of a particular content type for debugging or load testing. I use this function on Drupal 7 sites in my core module / feature to add a hook of:

http://mysite/random/my-content-type

(I use this instead of a view sorted by random because I want to be redirected to the full path of the node.)

Leaving off the content-type will use a random type from the array of valid content types I have provided. Providing an invalid content type will redirect it to an item from my core (or default) content-type.

@schnippy
schnippy / fontawesome_flags.md
Last active October 31, 2018 03:25
Using FontAwesome icons with On/Off states with Drupal 8 flags module
@schnippy
schnippy / TermReferenceBoost.php
Created August 10, 2018 22:13
Drupal 8.x Search API processor plugin for boosting search items by term reference field
<?php
// This plugin allows the administrator to boost items in an index based on a taxonomy term.
//
// Drop into an existing plugin module or create a new one, ex. create an info.yml file as
// modules/custom/search_api_boost_term_reference/search_api_boost_term_reference.info.yml
//
// name: 'Search API Boost by Term Reference'
// description: 'Define custom boost priority in Search API index by term reference field'
// core: 8.x
@schnippy
schnippy / export_query_csv.md
Last active September 6, 2019 23:00
TIL: How to export a MySQL query directly to CSV

TIL: How to export a MySQL query directly to CSV

I'm often running a single query that produces a set of results that I would like to export into a CSV.

For example, in a query against the url_alias table, I will want to grab the following and have it export into a spreadsheet rather than

mysql> SELECT source,alias FROM url_alias WHERE alias LIKE "library%";
+-----------+----------------------------------------------------------------+
| source    | alias                                                          |
+-----------+----------------------------------------------------------------+
@schnippy
schnippy / module_schema_query.md
Last active October 24, 2018 19:51
TIL: Checking module schema in database to confirm whether module updates have run

TIL: How to check module schema in database to confirm whether module updates have run

If I’m running database updates on a Drupal site and there is some question about whether or not the update fired, I can check this in the database itself from the command line.

Every module that has database updates will define these in their install file, ex. ctools.install and that file will have a number of install hooks that reference the schema number, ex:

/**
 * Revert the length of the ctools_object_cache.name column back to 128.
 */

Beyond module security updates: How to craft a holistic security strategy

This past year, Drupal site maintainers raced to patch their sites to address back-to-back critical security issues in Drupal 7/8, with exploits being detected in the wild within hours after the patches were released. These updates, while not out of the ordinary for open source software, occurred in an an increasingly complex security environment that is seeing a greater range of hostile actors executing more sophisticated, targeted, and damaging website attacks.

As a site owner, how worried should I be about these threats? What can I do besides keeping my modules patched? Are there other best practices for protecting my site from common attacks? How can I approach web security more holistically?

In this session, we will introduce a framework for understanding Drupal website security and how to assess possible solutions. This will include:

  • Understanding the nature of the current threat;
  • Discussion of common Drupal site vulnera
@schnippy
schnippy / github-multiple-deploy.md
Last active December 18, 2018 20:36
Managing multiple Github projects with multiple deploy keys on a single server

Managing multiple Github projects with multiple deploy keys on a single server

I have a number of projects on a single server that all have their own git repos on Github. My problem is that I need to create a separate deploy key for each one of these but I have to keep adding and re-adding the ssh-keys when I am doing deployments, ex:

eval "$(ssh-agent -s)"
ssh-add id_site1

I figured that there had to be a way to simplify this using SSH config but ended up with something like this which did not work, it always assumed the first entry in the list.

@schnippy
schnippy / pantheon_search_fix.md
Last active February 14, 2019 20:44
HOWTO: Fix Pantheon Search Instances on Multidev

HOWTO Fix Pantheon Search Instances on Multidev

If you have recently created a new multidev environment on Pantheon and search isn't working for you, this is because you will need to repost the schema and rebuild the search index to get it working.

In multidev, Pantheon is creating a new, full-stack environment for your site, including a new Solr instance but it does not provision a search core for you until you post the schema.

When you login to your environment, go to:

https://SITENAME/admin/config/search/pantheon
@schnippy
schnippy / machine_learning.md
Last active May 10, 2019 19:42
Practical Applications of Machine Learning with Drupal

Practical Applications of Machine Learning with Drupal

Machine learning is the hot new buzzword in the technology industry with heavy funding from the tech titans. It promises new solutions to complex problems and is already showing its potential with advances in voice assisted technologies and driverless cars capturing the headlines.

But what does any of this have to do with the work we do in Drupal? How can my organization or agency benefit from these technologies?

We are going to answer these questions in this presentation with a focus on the emerging Machine Learning as a Service (MLaaS) platforms that enable you to gain the benefits of Machine Learning without having to spend years collecting data and training a model.

In this presentation, we will address the following:

Drupal 8: Create controller to load random node by type

On many projects, I often have a need to be able to see a random node of a particular content type for debugging or load testing. I use this function on Drupal 8 sites in my core module to add a route of:

http://mysite/random/my-content-type

I use this instead of a view sorted by random because I want to be redirected to the full path of the node.

Leaving off the content-type will use a random type from the array of valid content types I have provided. Providing an invalid content type will redirect it to an item from my core (or default) content-type.